Change Docker default directory
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:
- CODE
{ "data-root": "/home/var" }
- Stop the docker service using
- BASH
systemctl stop docker
- Wait for sometime for all the docker containers to shutdown gracefully
- Reload the
systemd
configuration for new changes to be effective.- BASH
systemctl daemon-reload
- Create the new directory to be the new home for docker service. For example, if you want
/home/var
to be the home for Docker service, create the directory by using following command.
- BASH
mkdir /home/var
- Copy or sync all the current containers to the new root directory for docker.
- BASH
rsync -aqxP /var/lib/docker/ /home/var
- Start the docker service daemon
- BASH
systemctl start docker
- 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.
- BASH
docker ps -a