Docker: Change Location of Image Directory
Jan 24, 2021
Your default docker image directory is in /var/lib/docker. And the partition of that directory may be full. And you need to move it to the new created disk partition.
Here is the step by step instruction:
- Edit
/etc/docker/daemon.json
(if it doesn’t exist, create it)
{
"data-root": "/new/path/to/docker-data"
}
2. Stop docker daemon:
sudo systemctl stop docker
3. Copy everything from /var/lib/docker to new location
sudo rsync -axPS /var/lib/docker/ /new/path/to/docker-data
4. Start docker daemon:
sudo systemctl start docker
5. Verify your docker daemon is using the new location
sudo docker info | grep 'Docker Root Dir'
6 Check your docker is running
sudo systemctl status dockerdocker ps
7. If everything is OK, you may remove /var/lib/docker
sudo rm -r /var/lib/docker