Files
Wiki/Docker - Move Docker data directory to new location.md

1.2 KiB

kind, section
kind section
howto dev

The standard data directory used for docker is /var/lib/docker, and since this directory will store all your images, volumes, etc. it can become quite large.

Follow the steps below to move the Docker data directory to a new location. This makes especially sense if you want to avoid running out of disk space on your root partition.

Stop the Docker service and containers.

sudo systemctl stop docker
sudo systemctl disable docker
docker stop $(docker ps -aq)

Edit the config file:

sudo vi /etc/docker/daemon.json

And set the data root:

{
  "data-root": "/mnt/sdb/docker"
}

Verify the available disk space.

df -h

Move the current docker directory to the new directory.

sudo mv /var/lib/docker/ /mnt/sdb/docker/

Or copy the directory.

sudo rsync -avz /var/lib/docker/ /mnt/sdb/docker/
sudo mv /var/lib/docker/ /var/lib/docker.old

Restart the Docker deamon.

sudo systemctl start docker
sudo systemctl enable docker

Test containers are running.

docker ps -a
docker info -f '{{ .DockerRootDir}}'

Start the containers.

docker start $(docker ps -aq -f status=exited)