Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect contents of different Docker image layers?

Tags:

docker

My current understanding of a Docker image is that it is a collection of individual layers. Each layer only contains deltas that are merged via the union filesystem (which simply mounts all layers on top of each other). When instantiating an image, another (writable) layer is put on top that will then contain all container-specific changes that are persisted between restarts. Please correct me if I am wrong in any of the above.

I would like to inspect the contents of each of the various layers. I am particularly interested in inspecting the top-most layer to see whether my containerized app writes any data that would bloat the container, like a log or so. I am working on macOS, which does not store all the files in /var/lib/docker/, but seems to store them in a VM. I read about the docker-machine tools that make it easy to connect to the Docker engine via SSH, where one would be able to see and mount all layers. However, this tool seems to be discontinued.

Does anybody have an idea on 1) how to connect to the docker engine to get access to the layers and 2) how to find out what files are contained in a particular layer?

edit: It seems to be possible to use docker diff to see the file differences between the original image and the running container, which is what I mainly wanted to achieve, but the original questions remain.

like image 911
Sebastian P. Avatar asked May 19 '20 21:05

Sebastian P.


People also ask

How can we check the content of each layer in docker?

Use the docker history commandAnd use docker history to show the layers.

How do I inspect the content of a docker image?

To analyze a Docker image, simply run dive command with Docker "Image ID". You can get your Docker images' IDs using "sudo docker images" command. Here, ea4c82dcd15a is Docker image id. The Dive command will quickly analyze the given Docker image and display its contents in the Terminal.

Which command lists out all layers of a docker image?

In the command line interface (CLI), each layer of a Docker image is viewable under /var/lib/docker/aufs/diff, or via the Docker history command). Docker shows all top-layer images, Like the repository, tags and file sizes, by default.

How do I extract the contents of a docker image?

In order to extract image contents without dealing with many layers, a container should be created first. If docker run was already run, use that container, otherwise create a stopped container with docker create . Then use docker export or docker cp .


1 Answers

You can list the layers and their sizes with the docker history command. But to inspect the contents of all layers I recommend to use the dive tool.

like image 130
Stefan Feuerhahn Avatar answered Oct 29 '22 16:10

Stefan Feuerhahn