As discussed in one of the previous posts, docker is more focused on ease of use and not so much on the disk space efficiency out of the box. However, it is our responsibility to maintain adequate free space on hard disk and also do some kind of standardization. DevOps is not only about automation but it is also about standardization of process thereby removing any gotchas or discrepancy in the configuration. For example, we may like to store docker images in a separate directory that may be located on a mounted device storage or some other easy to navigate configuration.
By default, docker store containers and images in /var/lib/docker by default:

The location of image may vary on which version of storage driver associated with docker you are running on. The same info can be obtained by using docker info:

By default this will be aufs but can fall back to overlay, overlay2, btrfs, devicemapper or zfs depending on your kernel support. In most places this will be aufs but the RedHat uses devicemapper.
In the case of aufs:
/var/lib/docker/aufs/diff/<id> has the file contents of the images.
/var/lib/docker/repositories-aufs is a JSON file containing local image information. This can be viewed with the command docker images.
In the case of devicemapper:
/var/lib/docker/devicemapper/devicemapper/data stores the images
/var/lib/docker/devicemapper/devicemapper/metadata stores the metadata
Eventually, /var partition will start filling up as you use more and more images from repository. To change, we need to edit /etc/default/docker file and set DOCKER_OPTS with -g followed by new location. For example, in our case we created a new directory as /dockercontainers and then modify the file to look as below:

We then restart docker daemon or service by using appropriate command to our Operating system. For example, we would be using systemctl restart docker on Linux based distributions.
From now onwards, the newly created Docker containers and images would be stored in the new directory.
[…] Let’s have a look onto the docker storage options. Some documentation first. We know how to change the directory to store containers and images in Docker. In my CentOS 7.X, I see my daemon runs overlay2 and indeed the images after dowloaded are stored […]
LikeLike