Home > OS >  Docker service doesn't auto start after moving the docker image data directory to external driv
Docker service doesn't auto start after moving the docker image data directory to external driv

Time:07-01

Following this page, I have moved the docker data directory and created a symbolic link to it. It works. But everytime after rebooting my computer, the Docker service doesn't start automatically any more. How can I solve this problem?

journalctl -u docker.service returns:

Jun 30 10:29:55 ubuntu systemd[1]: Starting Docker Application Container Engine...
Jun 30 10:29:55 ubuntu dockerd[2358]: time="2022-06-30T10:29:55.426467188 10:00" level=info msg="S>
Jun 30 10:29:55 ubuntu dockerd[2358]: mkdir /var/lib/docker: file exists
Jun 30 10:29:55 ubuntu systemd[1]: docker.service: Main process exited, code=exited, status=1/FAIL>
Jun 30 10:29:55 ubuntu systemd[1]: docker.service: Failed with result 'exit-code'.
Jun 30 10:29:55 ubuntu systemd[1]: Failed to start Docker Application Container Engine.
Jun 30 10:29:57 ubuntu systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Jun 30 10:29:57 ubuntu systemd[1]: Stopped Docker Application Container Engine.
Jun 30 10:29:57 ubuntu systemd[1]: docker.service: Start request repeated too quickly.
Jun 30 10:29:57 ubuntu systemd[1]: docker.service: Failed with result 'exit-code'.
Jun 30 10:29:57 ubuntu systemd[1]: Failed to start Docker Application Container Engine.

Before moving the data directory "/var/lib/docker", it was a directory used by Docker, now it is a symbolic link that points to the external directory where the docker image data is stored. Why there is a mkdir command?

If I run dockerd, it returns:

INFO[2022-06-30T20:53:05.143671302 10:00] Starting up                                  
dockerd needs to be started with root privileges. To run dockerd in rootless mode as an unprivileged user, see https://docs.docker.com/go/rootless/

If I run sudo service docker start, docker can start without error. But I don't want to run this everyday. Docker used to start automatically. Any ideas?

CodePudding user response:

I was able to reproduce the error message with the same configuration:

 systemd[1]: Starting Docker Application Container Engine...
 dockerd[47623]: time="2022-06-30T16:36:20.047741616Z" level=in..
 dockerd[47623]: mkdir /data/docker: file exists
 systemd[1]: docker.service: Main process exited, code=exited, ..

The reason was that my external drive wasn't mounted yet.

Adding systemd mount/automount units resolve the issue. Or you can add your external drive to your /etc/fstab (Add nofail for avoid the 90 seconds wait when you don't have it with you).

Also from Docker doc:

You can configure the Docker daemon to use a different directory, using the data-root configuration option.

So editing your /etc/docker/daemon.json with:

{
  "data-root": "/data/docker"
}

is probably better than using symlinks.

  • Related