Home > Interesting > Change docker root directory

Change docker root directory

Problem:
The default docker root directory is /var/lib/docker. But /var had now run out of space and I needed to change to a different directory.

Solution:
Following the instructions here, I was able to make the change. https://linuxconfig.org/how-to-move-docker-s-default-var-lib-docker-to-another-directory-on-ubuntu-debian-linux

$ sudo systemctl stop docker.service
$ sudo systemctl stop docker.socket
$ sudo vim /lib/systemd/system/docker.service
Change
ExecStart=/usr/bin/dockerd -H fd://
To
ExecStart=/usr/bin/dockerd –data-root=/new/path/docker -H fd://

$ sudo mkdir -p /new/path/docker
# Optional if you want to move stuff over.
$ sudo rsync -aqxP /var/lib/docker/ /new/path/docker
$ sudo systemctl daemon-reload
$ sudo systemctl start docker

Note:
Everytime I updated docker, the system would replace the edited `/lib/systemd/system/docker.service` file. Which meant that running `docker image ls` would not show any images. The tutorial above uses an older format to change the directory. The current command should be

–data-root=/var/lib/docker Root of persisted Docker data

In case of errors use
`sudo systemd cat docker.service` to see what the errors are.
In my case, `Excess arguments.` gave me a clue to check that I was giving dockerd the correct arguments.

Source:
https://linuxconfig.org/how-to-move-docker-s-default-var-lib-docker-to-another-directory-on-ubuntu-debian-linux
https://docs.docker.com/engine/reference/commandline/dockerd/
https://stackoverflow.com/questions/35452591/start-request-repeated-too-quickly

Categories: Interesting Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.