By default, Docker stores the data of its images, containers and volumes in the
/var/lib/docker directory. Sometimes, you may want to request Docker to store its data in a different directory or partition.
For example, on my computers I keep separate partitions for root
/ and home
/home and the latter is much bigger than the former. So, I prefer that Docker use a directory in my
/home partition to store its data.
To change the data directory used by Docker:
/var/lib/dockerby removing all the images currently used by Docker:
$ docker system prune -a
Create a directory for Docker's data whereever you want. I created one in my home partition:
Add the following lines to the
"data-root": "/home/joe/docker_data", "storage-driver": "overlay2"
$ sudo systemctl restart docker
When you pull down images, you will now see the new data directory getting populated.