Docker is a lightweight virtualization and container management tool that can easily package applications into a container for easy deployment and management. In Docker, the image is the basis of the container, which contains the files and configuration information required for the application to run. However, many Docker users will face a problem, which directory is the image in? This article will introduce you to the location and specific operation methods of image storage.
Default storage directory for Docker images
Docker images are usually stored in the image subdirectory under the /var/lib/docker directory. Specifically, the subdirectories under the /var/lib/docker/image directory are named after the ID of the Docker image, and there is a repositories file in each subdirectory that records the information of the image. In addition, Docker images are also stored in the /var/lib/docker/image/devicemapper directory.
In addition to /var/lib/docker, Docker also allows users to store images in other directories, which only need to be set through the Docker engine configuration file.
How to operate the Docker image storage directory
In daily use, it may be necessary to operate the Docker image storage directory. The following will introduce you to several commonly used operating methods.
Method 1: Browse the /var/lib/docker directory
To view the location where the Docker image is stored, you can directly browse the /var/lib/docker directory. Under the /var/lib/docker/image directory, you can see a subdirectory named after the Docker image ID. These subdirectories contain all the files and configuration information required for the image.
For example, to view the storage location of the Docker image with ID abcdefg123, you can use the following command:
$ cd /var/lib/docker/image $ ls abcdefg123*
Method 2: Obtain information through the Docker image command
Provided by Docker engine A series of commands are provided to easily obtain information about Docker images. This includes commands to view the Docker image storage directory.
To view the location where the Docker image is stored, you can use the docker inspect command, which will output the detailed information of the Docker image, including the storage location.
$ docker inspect abcdefg123
The output result of this command includes the following similar fields:
"GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/7566467cd9c4198d10bade1b6900df12f761277c0ccde74b32f17b2a96b9a40c/diff:/var/lib/docker/overlay2/e0aa6d7483d848fc3c757deb20aa45e5706f38bbd18dd038f5bb5d08bd5d1b5f/diff:/var/lib/docker/overlay2/7729539e45e2689794f61f71de05a4431f208b97ec5db4f5b1fa22586c03f4d2/diff", "MergedDir": "/var/lib/docker/overlay2/59f6c953aab6a05eca62e0de6fd06c849f2219250dd96cb891375c8cc7df21cb/merged", "UpperDir": "/var/lib/docker/overlay2/59f6c953aab6a05eca62e0de6fd06c849f2219250dd96cb891375c8cc7df21cb/diff", "WorkDir": "/var/lib/docker/overlay2/59f6c953aab6a05eca62e0de6fd06c849f2219250dd96cb891375c8cc7df21cb/work" }, "Name": "overlay2" },
Among them, the LowerDir, MergedDir, UpperDir and WorkDir fields respectively represent the storage location of the Docker image.
Method 3: Modify the storage directory through the Docker engine configuration file
By default, the Docker image is stored in the /var/lib/docker directory. However, if the default storage location does not suit your needs, you can set it up by modifying the Docker engine's configuration file.
If you are using Docker CE, the configuration file is usually stored in the /etc/docker/daemon.json path. If the configuration file does not exist, you can create it manually.
The following is a simple example to store the Docker image in the /var/your/path directory:
{ "data-root": "/var/your/path" }
After completing the above settings, restart the Docker engine to take effect. You can use the following command to check whether the Docker image storage directory has been modified successfully:
$ docker info | grep 'Docker Root Dir'
Summary
Docker image is the basis of the container, and its storage location is an important issue for Docker users. In this article, we introduce the default storage directory of Docker images and three operation methods. I hope this article can help you better understand the relevant knowledge of Docker image storage directory.
The above is the detailed content of docker. Which directory is the image in?. For more information, please follow other related articles on the PHP Chinese website!