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.
- Stop docker daemon
$ sudo service docker stop
- 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"
}
- Copy the current data directory to the new one.
$ sudo rsync -aP /var/lib/docker/ /disk2/docker
- Rename the old docker directory
$ sudo mv /var/lib/docker /var/lib/docker.old
- 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