Inspecting Docker Image Details
Once you have a Docker image, it's important to understand how to inspect its details. Docker provides several commands and options to help you get a deeper understanding of your images.
Listing Docker Images
To list all the Docker images on your system, you can use the docker images
command:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-app latest 6a1a3a2a9d0c 10 minutes ago 194MB
ubuntu 22.04 9141669e8366 2 weeks ago 72.8MB
This command will display the repository name, tag, image ID, creation time, and image size for each image on your system.
To get more detailed information about a specific Docker image, you can use the docker inspect
command:
$ docker inspect my-app
[
{
"Id": "sha256:6a1a3a2a9d0c2f7d5c0f6c6b9c8d7e6c5d4c3b2a1",
"RepoTags": [
"my-app:latest"
],
"RepoDigests": [],
"Parent": "sha256:9141669e8366a3c6d1c3d9d7e6c5d4c3b2a1",
"Comment": "",
"Created": "2023-04-17T12:34:56.789012Z",
"Container": "4c5e6d7a8b9c0d1e2f3g4h5i6j7k8l9m",
"ContainerConfig": {
...
},
"DockerVersion": "20.10.14",
"Author": "",
"Config": {
...
},
"Architecture": "amd64",
"Os": "linux",
"Layers": [
"sha256:9141669e8366a3c6d1c3d9d7e6c5d4c3b2a1",
"sha256:6a1a3a2a9d0c2f7d5c0f6c6b9c8d7e6c5d4c3b2a1"
]
}
]
The docker inspect
command provides a wealth of information about the image, including its ID, tags, parent image, creation time, configuration, and the layers that make up the image.
Inspecting Image Layers
To get a more detailed view of the layers that make up a Docker image, you can use the docker history
command:
$ docker history my-app
IMAGE CREATED CREATED BY SIZE COMMENT
6a1a3a2a9d0c 10 minutes ago COPY . /app 1.024kB
9141669e8366 2 weeks ago /bin/sh -c #(nop) CMD ["python3"] 0B
9141669e8366 2 weeks ago /bin/sh -c apt-get update && apt-get install -y 20.3MB
9141669e8366 2 weeks ago /bin/sh -c #(nop) ADD file:0e56c8c4a5d1a0e9c1d 72.8MB
This command shows the individual layers that make up the Docker image, including the commands used to create each layer and the size of each layer.
By understanding how to inspect Docker image details, you can gain a deeper understanding of the structure and composition of your images, which can be helpful for troubleshooting, optimization, and sharing your images with others.