Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dunderrrrrr/154758ba5c22e03be2e430dbf65e5362 to your computer and use it in GitHub Desktop.
Save dunderrrrrr/154758ba5c22e03be2e430dbf65e5362 to your computer and use it in GitHub Desktop.

Move docker data/volumes directory to another location on Ubuntu

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 in a relative small amount of time.

Here's a guide how to change that folder to another location, for example another disk.

  1. Stop docker daemon
$ sudo service docker stop
  1. Add a configuration file to tell the docker daemon what is the location of the data directory. Create and edit /etc/docker/daemon.json.
$ sudo nano /etc/docker/daemon.json
{ 
   "data-root": "/disk2/docker" 
}
  1. Copy the current data directory to the new one.
$ sudo rsync -aP /var/lib/docker/ /disk2/docker
  1. Rename the old docker directory
$ sudo mv /var/lib/docker /var/lib/docker.old
  1. Restart the docker daemon
$ sudo service docker start

Your containers should now be starting and reading/writing to the new location.

If you feel crazy, delete the old path.

$ sudo rm -rf /var/lib/docker.old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment