Move the docker data directory

The default location for the docker data directory, when using overlay2 storage driver is /var/lib/docker. Maybe you want to move it to another location, and it’s actually pretty easy.

  1. Stop the docker service:
    sudo systemctl stop docker.service
  2. Copy the docker folder to the new location:
    sudo cp -rp /var/lib/docker /path/to/new/location
    The p in -rp will preserve ownership, permissions and timestamps
  3. Tell the docker daemon about the new location by editing the /etc/docker/daemon.json file with the following:
{
    "data-root": "/path/to/new/location"
}

4. Start the docker service:
sudo systemctl start docker.service

Thats it, the docker directory has been moved.

The above guide is tested on Ubuntu 20.04, but will probably be very much alike on other flavours.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.