Error starting container after moving docker root directory

Hi, I installed Docker CE on my machine after upgrading my OS. Before starting the daemon, I copied over the docker folder from my backup to the new disk. Previously, docker data was in /var/lib/docker, but my new disk is mounted in /srv, and moved the data to /srv/docker. The backup was on disk with the same permissions as the original, so copied all the docker folder with cp -rpv.
Containers that don’t have volumes work fine, and I’m even able to see past container executions with docker ps -a. However, when I try to start a container with a volume, I get this error:

Error response from daemon: error evaluating symlinks from mount source "/var/lib/docker/volumes/esdata/_data": lstat /var/lib/docker: no such file or directory
Error: failed to start containers: admiring_yalow

How can I fix this?

Here’s some information about my system:

$ docker version
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:48:47 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:19:08 2018
  OS/Arch:          linux/amd64
  Experimental:     false

OS: Fedora 29 x64

$ uname -a
Linux telperion 4.19.4-300.fc29.x86_64 #1 SMP Fri Nov 23 13:03:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Let me know if you need more information.
Thanks!

1 Like

Hi

So how did you tell docker that you moved the data? created a symlink?
You can try and add “data-root” to your daemon.json https://docs.docker.com/engine/reference/commandline/dockerd/

I created a systemd service override: created a file in /etc/systemd/system/docker.service and changed the ExecStart config:
ExecStart=/usr/bin/dockerd -g /srv/docker -H unix://

Okay…
im not sure if this would work, but.

#Get the full id of the container:
docker ps --no-trunc --format "table {{.ID}}\t{{.Names}}"

#Edit the container config (backup first)
EDITOR /srv/docker/containers/FULLID/config.v2.json

In that file, you should be able to see the path for the mounts, if they are still pointing to /var/lib/docker/vol…
You can try and change that to your new path.

3 Likes

Thanks a lot! Making the change in that file worked perfectly :tada:
For the record, I needed to change that file while the docker daemon was stopped, because if I changed it while it was running, the file was restored back when I tried to run the container :confused:

There are countless pages out there describing how to move your docker directory to another location. None of them mentioned @terpz tip about the config.v2.json files containing the absolute path to the original location.

Thanks for the tip, you absolutely can’t move your docker storage location without also updating these files.

2 Likes

Here is a one-liner to fix all occurences of the old data dir:

sed -i 's%/var/lib/docker%/new/dir%g' /new/dir/containers/*/config.v2.json

Leave out -i to test your changes.

2 Likes
sed -i 's%/var/lib/docker%/new/dir%g' /new/dir/containers/*/config.v2.json

This one liner didn’t work for me. So I replaced * with each container id and ran the command for every container which worked for me.

sed -i 's%/var/lib/docker%/NEW/DOCKER/PATH%g' /NEW/DOCKER/PATH/containers/CONTAINER_ID/config.v2.json

I got full container ids with this command

docker container ls --no-trunc --filter "status=exited" --format "table {{.ID}}"

Hi everyone, I am struggeling with the same issue: docker consumed a lot of space on the /var volume so I moved it to a new location (so far so good) and used the proposed commands here, to update the config.v2.json files (Thanks a lot for this convenient solution) but I am struggling with one container: Portainer.

I created it that way:
docker volume create portainer_data

docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

The sed-reccomendation fixes the path in config.v2.json but when I try to start the container (docker container star portainer) I get:

Error response from daemon: error evaluating symlinks from mount source "/var/lib/docker/volumes/portainer_data/_data": lstat /var/lib/docker: no such file or directory

and when editing config.v2.json, I see, that the changes made before are gone and there are still the old paths. What am I doing wrong or how can I fix it ?

How exactly did you do that? Did you move the data and create a symlink (i hope not!), Did you move the data and mount the new location (either by mounting a filesystem into that folder or by bind mounting a folder into that folder)? Did you change the data-rootsetting in /etc/docker/deamon.json?

  • stopped docker
  • created a new directory on a bigger partition
  • copied (rsync) the old content to the new location
  • added data-root, pointing to the the new location in /etc/docker/daemon.json
  • renamed the old docker /var/lib/docker to /var/lib/docker.old
  • re-started docker

Then all, except for two, containers instantly started fine from the new location.

Then I used

sed -i 's%/var/lib/docker%/new/dir%g' /new/dir/containers/*/config.v2.json

to fix “orphaned” paths in the config.v2.json - files, which fixed one of the two containers issue.

But then I ended with what I described: Portainer does not want to start with the error:

Error response from daemon: error evaluating symlinks from mount source "/var/lib/docker/volumes/portainer_data/_data": lstat /var/lib/docker: no such file or directory

I then restricted the sed command, to the folder with the config.v2.json in it and checked the file manually: All wrong references were fixed.
When starting portainer however, I get the error message again and the config.v2.json contains the old links again.

It’s a clean approach.

It is quite odd that you modified the config.v2.json with stopped docker engine. Then started the engine and see that all changes are reverted. Just to be sure: this does only happen for the Portainer container, and not with the others?

Did you make sure the new location uses the same filesystem type the old used, and that the same storage driver is used by docker?

I found the issue:

You emphasized the “with stopped docker engine”. So I repeated the step again and saw an error message I had ignored in the first place:

'Warning: Stopping docker.service, but it can still be ac                                                                                                                                                                                                      tivated by:  docker.socket

So I had to systemctl stop docker.socket and guess what: this time no-one did revert modifications to config.v2.json

1 Like