Home > Article > Operation and Maintenance > Check where the docker image is pulled and placed
Docker is an open source container technology that can be used to build, publish and run applications. By using Docker images, users can download and install pre-built applications or container environments simply and quickly.
Docker images are composed of multiple layers (Layer), each layer contains a snapshot of the file system. When a user pulls a Docker image, they actually obtain all the layers of the image from the Docker Registry and combine them to build a complete Docker image.
So, where is the local storage location of the Docker image? This article will introduce it to you in detail.
First, we need to view the current local Docker image list. Enter the following command in the terminal:
docker images
After execution, a list of all Docker images on the machine will be listed, including image ID, image name, image label, image size and other information. As shown in the figure below:
#As you can see from the above figure, each image has a unique ID, a name and some tags (also called versions). Among them, the REPOSITORY field represents the name of the image, the TAG field represents the label of the image, and the IMAGE ID field is the unique identifier of the image.
In Docker, each image is composed of multiple layers (Layer). Therefore, when a user downloads or builds a Docker image, all layers of the image are actually downloaded to local storage.
In the Linux system, the Docker image is actually stored in the /var/lib/docker
directory. Enter the following command in the terminal:
sudo ls -l /var/lib/docker/
After execution, the terminal will display a list of all files and folders in the /var/lib/docker/ directory. Among them, the /var/lib/docker/image
folder is the main location where Docker stores images. As shown in the figure below:
In the /var/lib/docker/image/overlay2/imagedb/content/sha256
directory, all existing The downloaded Docker image (named by the image ID), which is the storage location of all layers. In each image ID directory, there is a file named "real" or "diff", which represents the storage location of this layer.
For each layer of the Docker image, its storage location can be confirmed by executing the following command:
docker history <image_name>:<tag>
For example, for the nginx image, executing the command:
docker history nginx:latest
will output the following results:
IMAGE CREATED CREATED BY SIZE COMMENT 84cf8d0a2e04 3 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 3 weeks ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B <missing> 3 weeks ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 3 weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B <missing> 3 weeks ago /bin/sh -c set -x && apt-get update && ap… 68.2MB <missing> 3 weeks ago /bin/sh -c #(nop) ENV NJS_VERSION=2.1.0.6 0B <missing> 3 weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.16.1 0B <missing> 4 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B <missing> 4 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 4 weeks ago /bin/sh -c #(nop) ADD file:7fbfce9f6a99e63a5… 63.2MB
Among them, the SIZE field of each layer indicates the actual space occupied by the layer. The first column of the output result of this command is the ID of each layer of the Docker image, which represents each layer of the image from top to bottom.
We can confirm the specific storage location of each layer based on the output of this command. For example, in the output of the above command, the last column is the description information of the layer, which includes the original command and parameters of the layer.
For the first layer of the nginx image (ID is "84cf8d0a2e04"), the CMD of this layer is "CMD ["nginx" "-g" "daemon..."", which means starting the nginx service; for the following Each layer contains other configurations or commands. Therefore, we can roughly guess where each layer of the Docker image is stored.
With the above command, users can view the locally stored Docker image under the Linux system. The layer of the Docker image is stored in the /var/lib/docker/image/overlay2/imagedb/content/sha256
directory with the image ID as the folder name. Each layer is stored in a "real" or "diff" file respectively.
For the storage location of each layer of mirroring, you can view the storage location of the layer by executing the docker history
command and look for the description information of the layer in the output results to roughly guess the storage location of the layer.
When using Docker images and containers, understanding the storage location of Docker images can better manage local storage space, as well as backup and restore Docker images and containers.
The above is the detailed content of Check where the docker image is pulled and placed. For more information, please follow other related articles on the PHP Chinese website!