Last active
April 4, 2024 09:13
-
-
Save nileshsimaria/ec2ea6847d494d2a1935c95d7c4b7155 to your computer and use it in GitHub Desktop.
Change docker's default /var/lib/docker to different directory on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Take a backup of docker.service file. | |
$ cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.orig | |
2. Modify /lib/systemd/system/docker.service to tell docker to use our own directory | |
instead of default /var/lib/docker. In this example, I am using /p/var/lib/docker | |
Apply below patch. | |
$ diff -uP -N /lib/systemd/system/docker.service.orig /lib/systemd/system/docker.service | |
--- /lib/systemd/system/docker.service.orig 2018-12-05 21:24:20.544852391 -0800 | |
+++ /lib/systemd/system/docker.service 2018-12-05 21:25:57.909455275 -0800 | |
@@ -10,7 +10,7 @@ | |
# the default is not to use systemd for cgroups because the delegate issues still | |
# exists and systemd currently does not support the cgroup feature set required | |
# for containers run by docker | |
-ExecStart=/usr/bin/dockerd -H unix:// | |
+ExecStart=/usr/bin/dockerd -g /p/var/lib/docker -H unix:// | |
ExecReload=/bin/kill -s HUP $MAINPID | |
TimeoutSec=0 | |
RestartSec=2 | |
3. Stop docker service | |
$ systemctl stop docker | |
4. Do daemon-reload as we changed docker.service file | |
$ systemctl daemon-reload | |
5. rsync existing docker data to our new location | |
$ rsync -aqxP /var/lib/docker/ /p/var/lib/docker/ | |
6. Start docker service | |
$ sysctl docker start |
@pumuugel82 it's worked for me, thank you
@pumuugel82 #6. sudo systemctl deamon-reload <---- daemon spelling correction :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your option
-g /p/var/lib/docker
doesn't work for me. But a:sudo /var/lib/dockerd --help
revealed that there is a option
--data-root
. After copying all the contents from/var/lib/docker
to/data/var/lib/docker
(/data is my new directory pointing to some new bigger virtual disk as I am running fedora 37 in libvirt) and after modify the systemd's override via:sudo systemctl edit docker
and pasted the following content:
it works perfect.
Pay attention: The value for --data-root has to end with a slash "/". The first shot didn't work as I missed it. After appending the "/" it worked.
Regards
EDIT
Of course the sequence of editing is as follows: