Problem 1 - need move /var/lib/docker
to large volume
Our local linux disk volume is under 30GB, so it will be quite challenge for our docker images, which take a lot of space under /var/lib/docker
folder and quickly run out of space.
Solution for Problem 1
It is possible to follow this artile - Use a Different Volume For Your Docker Images in Ubuntu that mount a new volume folder e.g. /dev/sda2
for /var/lib/docker
and add the following line
/dev/sda2 /var/lib/docker ext4 defaults 0 1
in /etc/fstab
so the mount also happen during startup linux.
A quick tip to get volume type is using command df -T
What I did in fact follow this artile - How to move docker data directory to another loccation on Ubuntu
- stop the docker daemon
$ sudo service docker stop
and make sure that docker is not running
$ ps faux | grep -i docker
- make the folder and
rsync
the files
$ mkdir /mnt/docker
$ rsync -avxP /var/lib/docker/ /mnt/docker
- Update docker configuration
- Add a configuration file and tell the docker daemon what is the location of the data directory by creating a file called
daemon.json
under directory/etc/docker
. the file should have the content:
- Add a configuration file and tell the docker daemon what is the location of the data directory by creating a file called
{
"data-root":"/mnt/docker"
}
- Update the docker service by editing
/lib/systemd/system/docker.service
Find the following line
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
and update to
ExecStart=/usr/bin/dockerd -g /mnt/docker -H fd:// --containerd=/run/containerd/containerd.sock
- Re-start the docker daemon
sudo service docker start
# reload docker serivce configuration
sudo systemctl daemon-reload
- test by the following command after you pull an image
docker inspect image_id | grep WorkDir
Problem 2 - After linux reboot, docker images are gone
The docker images under /mnt/docker
are gone, e.g. /mnt/docker/overlay2
has no docker images that we pulled fromm DockerHub.
See github discussion https://github.com/moby/moby/issues/36149
and PR https://github.com/moby/sys/pull/62
Solution for Problem 2
No solution yet, keep looking! So far, have to re-pull the docker images.
Top comments (1)
That's it. Thanks for sharing.