Docker uses (/var/lib/docker) as default root directory to provide storage. We will see how to change this root directory to some other directory, let’s say ‘/home/techrunnr/docker’.
Lets login to our docker server and see the running containers through below command,
Now we will see the running containers respective file-system as below
So before changing docker’s default root directory, please make sure that new directory is existing,
Stop all running docker containers and then docker daemon. Move “/var/lib/docker” directory to the place where you want to have this data.
and then create symlink for this docker directory in /var/lib path:
Since SELinux is enabled for the production environment, Docker will need permission to write into the new directory. We need to change the SELinux file contexts when using a custom Docker Data root, by default in RHEL/Centos provides SELinux file context default docker data root directory /var/lib/docker, and other locations.
In order to make the changes in the SELinux file context types in custom Docker data root, we should execute the below commands:
Start docker daemon and containers.
Let’s start any one of our containers and see the docker’s root directory,
Now we have changed the docker root directory from ‘/var/lib/docker’ to ‘/home/techrunnr/docker/ and set SELinux file contexts for new Docker data root.
© 2019, Techrunnr. All rights reserved.