Skip to content

Instantly share code, notes, and snippets.

@nileshsimaria
Last active April 4, 2024 09:13
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save nileshsimaria/ec2ea6847d494d2a1935c95d7c4b7155 to your computer and use it in GitHub Desktop.
Save nileshsimaria/ec2ea6847d494d2a1935c95d7c4b7155 to your computer and use it in GitHub Desktop.
Change docker's default /var/lib/docker to different directory on Ubuntu
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
@vijaykumar3060
Copy link

@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