Bobcares

How to change Docker directory

by | Aug 29, 2016

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:

Docker default data directory

Docker default data directory

 

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.

Setup and manage your Docker system

GET IN TOUCH WITH THE DOCKER EXPERTS NOW!

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:

Docker default directory

Docker default directory

 

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.

Change Docker directory in configuration file

Change Docker directory in configuration file

 

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:

Docker directory changed to /mnt

Docker directory changed to /mnt

 

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. ]

How to change the existing Docker image directory

In some cases, it may be required to move the already existing data also from the old directory to the new one.

To move the old images and containers, we first moved the directory contents and then created a symbolic link with these steps:

1) Stop the docker service

service docker stop

2) Backup the existing directory ‘/var/lib/docker’.

3) Move the old directory to the newly created partition ‘/mnt/docker’

mv /var/lib/docker /mnt/docker

4) Create a symlink between the two directories:

ln -s /mnt/docker /var/lib/docker

5) Start the docker service

service docker start

6) Confirm that the containers are working fine.

[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]

In short..

Today we discussed how to change the default directory of Docker. The directory changes should be done with special caution to avoid any mess up.

Other points to be considered are: proper mounting of the new partition, assigning adequate permissions and ownership to the folders, usage of Docker containers, etc.

At Bobcares, we have 24/7 custom monitoring scripts to check the disk space usage. Whenever disk usage goes above 75%, our engineers take prompt measures to ensure enough disk space.

Our team also set custom scripts to rotate log files and delete unwanted files to prevent disk usage from over-shooting. Backups are always taken as a precaution.

We also give recommendations to server owners on how to manage their server resources effectively. If you’d like to know how to get the best out of your servers, we’d be happy to talk to you.

 

 

 

Disk space issues in Docker ?

Wish you had more time to focus on your business? Let us help you.

Our engineers will assist you to setup, monitor and manage your Docker infrastructure 24/7.

GET IN TOUCH WITH THE EXPERTS NOW!

var google_conversion_label = "owonCMyG5nEQ0aD71QM";


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.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.