-
-
Save nileshsimaria/ec2ea6847d494d2a1935c95d7c4b7155 to your computer and use it in GitHub Desktop.
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 |
You are going to get a very nasty surprise when docker updates :)
Try this?
sudo systemctl edit docker
- Add JUST this (using your example):
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -g /p/var/lib/docker -H unix://
I found a great explanation here, which explains better than I can: https://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -g /p/var/lib/docker -H unix://
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:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --data-root /data/var/lib/docker/ -H fd:// --containerd=/run/containerd/containerd.soc
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:
- sudo systemctl stop docker
- sudo systemctl status docker #check that docker is relay inactive
- sudo cp -r /var/lib/docker /directory-for--data-root
- sudo systemctl edit docker
- change and save the override with values like above "ExeStart= ...." (yes ExecStart is needed two times, 1. to reset, 2. with new value)
- sudo systemctl deamon-reload
- sudo systemctl start docker
- be happy
@pumuugel82 it's worked for me, thank you
@pumuugel82 #6. sudo systemctl deamon-reload <---- daemon spelling correction :-)
this is al fun and games until your package manager updates the docker.service file and suddenly everything breaks.