Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to change Docker data directory

📅 2020-Jul-09 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ docker ⬩ 📚 Archive


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:

$ docker system prune -a
"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.