Change Data Directory of Docker

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.


	"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.

profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.