ShinChven's Blog

Move Docker data-root

Sun Nov 22 2020

Do you ever feel files in /var/lib/docker are taking so much space of your system partition's storage? That's because the directory is storing docker's images and containers' file-systems, and we all know that those things are really big.

Fortunately, you can actually move docker's data-root to another path by configuring /etc/docker/daemon.jsondaemon configuration file.

WARING: if you are migrating an existing docker data root

Some existing containers may encounter error after migration, you must:

  • Make sure that everything you want to save has been backed up or persisted out of the container(on host) by mirroring data volumes.
  • Make sure all containers can be recreated.

It is a good practice to always persist data out of docker container, all containers and images should be seemed as app binaries.

Before You Start

You should stop the docker daemon:

systemctl stop docker

Copy Existing

It is recommended to copy everything instead of moving them, so that you can still find a way back when error occurred.

cp -r /var/lib/docker /path/to/docker/data/root

data-root Configuration

By adding or modifying data-root in /etc/docker/daemon.json, the configuration is done.

    "data-root": "/path/to/docker/data/root"


systemctl start docker