Code Yarns β€πŸ‘¨β€πŸ’»
Tech Blog ❖ Personal Blog

How to change Docker data directory

πŸ“… 2020-Jul-08 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ docker ⬩ πŸ“š Archive

Problem

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.

Solution

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.


Β© 2022 Ashwin Nanjappa β€’ All writing under CC BY-SA license β€’ 🐘 @codeyarns@hachyderm.io β€’ πŸ“§