When we create Docker objects such as images, containers, volumes, etc., all these objects are stored inside a directory in our local machine. By default, all the Docker objects are stored in the following directory.
Moreover, the contents stored inside the /var/lib/docker path depend on the storage driver that you are using as well. Let’s first understand the docker storage drivers in short.
Docker Storage Drivers
In an ideal case, very little amount of data gets written onto the writable layer of a Docker container. And 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 and this is exactly where storage drivers in Docker come in.
Docker uses a pluggable architecture to support various different storage drivers. It totally depends upon these storage drivers that how the Docker images and containers are managed and stored in our Docker host.
The different types of storage drivers supported by Docker are - overlay2, aufs, devicemapper, 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
You can set the storage driver in two different ways.
You can either use the -s or --storage-driver option along with the Docker run command. Or you can edit the /etc/docker/daemon.json file and include the following lines.
Now that we have understood the basics of storage drivers in Docker, let’s see the different behaviors 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 -
The metadata about the images is located in the JSON and layersize files in the following directory.
In the above paths, the driver-name is the default storage driver used by Docker in your machine and the id refers to the image ID.
If your host machine uses aufs storage driver for Docker, then you can look for image file contents in the following directory.
The directory mentioned below contains the local image information in a JSON file. This information can be retrieved using the Docker images command in the command line.
In the case of the devicemapper storage driver, the system stores the image information in the following directory.
The metadata related to the images can be found on the path -
It’s important to note that these files are not that big as they might seem to be because of the fact that they are thin provisioned sparse files.
If you are using Docker inside Mac through a Virtual Machine, then you can find all your container and image information in the following directory.
C:\Users\Public\Documents\Hyper-V\Virtual hard disks\MobyLinuxVM.vhdx
To sum up, the Docker storage drivers play a huge role in deciding the storage location of your metadata as well as all other information related to all the 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. Moreover, the location various with respect to the type of operating systems as well.