Docker saves it’s images, volumes, networks etc in /var/lib/docker
. Sometimes it is useful to move this directory to another location. For example a separate disk mounted under /opt
.
This can be done by specifying the data-root
in the /etc/docker/daemon.json
configuration-file.
/etc/docker/daemon.json
{
"data-root": "/opt/docker"
}
For these changes to take affect, you need to restart the Docker-service.
Warning! This will restart your containers as well. That means a short downtime for your services.
If you want to migrate an existing installation, you should copy the present data into the new directory before restarting the service.
If you have a new Docker installation, you can skip this step.
[tux@server]$ sudo cp -r /var/lib/docker /opt/docker
Now restart the service.
[tux@server]$ sudo systemctl restart docker
From now on all data will be saved in the new directory.