Move Docker root directory

To avoid the system drive being filled up as the volumes grow I like to move my docker root directory to a dedicated volume. In this example a new drive is added to my docker server which is mounted as /vol/01/ so make sure you have your destination directory setup and change /vol/01 respectively.

First stop Docker and move its defaults directory (/var/lib/docker) to its new home (/vol/01 in this case):

sudo systemctl stop docker && sudo systemctl stop docker.socket
sudo mv /var/lib/docker /vol/01/

Edit (or create) the file /etc/docker/daemon.json and add:

{
"data-root": "/vol/01/docker"
}

If you have existing Docker instances you will need to edit their config.v2.json files:

sed -i 's%/var/lib/docker%/vol/01/docker%g' /vol/01/docker/containers/*/config.v2.json

Now restart docker and your containers should be running at its new location:

sudo systemctl start docker

You can check if the root directory is moved using the docker info command:


# docker info | grep -i root
 Docker Root Dir: /vol/01/docker
Category: linux | LEAVE A COMMENT