The Docker Images and other objects are store inside the docker directory in the local machine. They are depending upon the default storage driver used by the machine.
When we create Docker objects such as images, containers, volumes, etc. all these objects are store inside a directory in our local machine. By default, all the Docker objects are store in the following directory.
/var/lib/docker/<storage-driver>
The contents stored inside the /var/lib/docker path depend on the storage driver that you are using as well. Now let us first understand the docker storage drivers.
Docker Storage Drivers
In an ideal case, very little amount of data are written onto the writable layer of a Docker container. We use volumes in Docker to write such data. But there are some workloads that require us to be able to use the container’s writable layer to write data. This is exactly where storage drivers in Docker come in.
Docker uses a pluggable architecture to support various different storage drivers. It is totally depend on the storage drivers that how Docker images and containers are manage and store in our Docker host.
The different types of storage drivers supported by Docker are – overlay2, aufs, device-mapper, btrfs, zfs, vfs. The current default Docker Storage driver is overlay2.
To check the default storage driver, you can use the following command.
$ docker info
We can set the storage driver in two different ways.
We can either use the -s or –storage-driver option with Docker run command or we can edit the /etc/docker/daemon.json file. Then we can include the following lines.
{
"storage-driver":"aufs"
}
Now, we have understood the basics of storage drivers in Docker. Let us see the different behaviours of different drivers when it comes to storing Docker objects in local machines.
Storage of Docker Images and Other Objects
The driver-specific storage for Docker image contents will be in the path :
/var/lib/docker/{driver-name}
The metadata about the images is located in the JSON and layersize files in the following directory.
/var/lib/docker/graph/<id>
In the above paths, the driver-name is the default storage driver use by Docker in our machine . And the id refers to the image ID.
If our host machine uses aufs storage driver for Docker then we can look for image file in following directory:
/var/lib/docker/aufs/diff/<id>
The directory mentioned below contains the local image information in a JSON file. This information can be retrieve using the Docker images command in the command line.
/var/lib/docker/repositories-aufs
In the case of the device-mapper storage driver, the system stores the image information in the following directory:
/var/lib/docker/devicemapper/devicemapper/data
The metadata related to the images can found in the following way:
/var/lib/docker/device-mapper/device-mapper/metadata
If we are using Docker inside Mac through a virtual machine then we can find all our container and image information in the following directory:
~/Library/Containers/com.docker.docker/Data/vms/0/Docker.raw
Conclusion:
The Docker storage drivers play a huge role in deciding the storage location of our metadata with all other information related to all Docker objects including images, containers, volumes, etc. However, the base directory path is /var/lib/docker and the subsequent directories depend upon the type of storage driver. And the location varies with respect to the type of operating systems as well.