How to change Docker directory
Maintaining adequate disk space is a crucial task we perform in our outsourced server management services. Lack of free space can often lead to server crashes.
In Docker machines, ‘/var/lib/docker’ is the directory where the Docker images and the container data are stored by default, when Docker is installed:
But when the /var partition gets filled up as more and more containers are created, the system may soon run out of space. That’s when we need to change the default directory for Docker images.
Today we’ll discuss how to change the default installation directory for Docker.
How to change Docker default directory
To change Docker’s images directory ‘/var/lib/docker’ to another partition with more space, the option ‘-g’ is used with the Docker daemon.
For instance, in our Docker machine, the default directory was ‘/var/lib/docker/aufs’ as seen:
Here’s how we changed it to another directory:
1. Since our /var partition was running out of space, we created a new partition ‘/mnt/docker’.
2. We then edited the Docker configuration file ‘/etc/default/docker’ and gave the start-up option -g to specify this new directory.
3. We then restarted the Docker service
root default # service docker restart docker stop/waiting docker start/running, process 20081
4. After the restart, Docker started using the new directory ‘/mnt/docker’ as seen here:
From now onwards, the newly created Docker containers and images would be stored in the new directory ‘/mnt/docker’.
[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]
Bobcares provides Outsourced Hosting Support and Outsourced Server Management for online businesses. Our services include Hosting Support Services, server support, help desk support, live chat support and phone support.