The following config will guide you through a process of changing the docker's default /var/lib/docker storage disk space to another directory.
-
Login to CentOS and edit or create
/etc/docker/daemon.json -
Add the following piece of code to the file you have just opened:
-
{ "data-root": "/home/var" }
-
-
Stop the docker service using
-
Bashsystemctl stop docker
-
-
Wait for sometime for all the docker containers to shutdown gracefully
-
Reload the
systemdconfiguration for new changes to be effective.-
Bashsystemctl daemon-reload
-
-
Create the new directory to be the new home for docker service. For example, if you want
/home/varto be the home for Docker service, create the directory by using following command. -
Copy or sync all the current containers to the new root directory for docker.
-
Bashrsync -aqxP /var/lib/docker/ /home/var
-
-
Start the docker service daemon
-
That's it. If you have done everything correctly, Docker service should be started normally. Verify all the containers are up and running successfully by running following command. docker ps -a