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.
Use the docker history commandAnd use docker history to show the layers.
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.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With