Do you ever feel files in
/var/lib/docker are taking so much space of your system partition’s storage? That’s because the directory is storing docker’s images and containers’ file-systems, and we all know that those things are really big.
Fortunately, you can actually move docker’s
data-root to another path by configuring
/etc/docker/daemon.jsondaemon configuration file.
Some existing containers may encounter error after migration, you must:
- Make sure that everything you want to save has been backed up or persisted out of the container(on host) by mirroring data volumes.
- Make sure all containers can be recreated.
It is a good practice to always persist data out of docker container, all containers and images should be seemed as app binaries.
You should stop the docker daemon:
systemctl stop docker
It is recommended to copy everything instead of moving them, so that you can still find a way back when error occurred.
cp -r /var/lib/docker /path/to/docker/data/root
By adding or modifying
/etc/docker/daemon.json, the configuration is done.
systemctl start docker