At some point we all want to store Docker images and volumes on a different drive, to avoid the system drive being filled up as the volumes grow. Here’s how.

First stop the docker service. Then the volumes can be moved from the default location at /var/lib/docker to the new location.

$> sudo service docker stop
$> sudo mv /var/lib/docker /srv/new-drive/new-docker-root

Next the configuration of the docker daemon is edited to point to the new location of the volumes.

$> sudo nano /etc/docker/daemon.json
"data-root": "/srv/new-drive/new-docker-root"

The next step may not be necessary, but it is a good habit to do it anyway. Kindly reload the docker daemon and restart the docker service. Forgetting this step can cause a lot of lost time and confusion.

$> sudo systemctl daemon-reload
$> sudo service docker start

Having a look at the output of docker info shows that the docker volumes are successfully recognized at their new location.

$> docker info
Total Memory: 15.35GiB
Docker Root Dir: /srv/new-drive/new-docker-root
Debug Mode: false

Looks alright to me. Finally start up those docker containers again.

$> docker-compose up -d
Creating network "nextcloud_default" with the default driver
Creating nextcloud_db_1 … done
Creating nextcloud_app_1 … done

That’s it.