1

Updated per feedback

For versions of Docker equal to or later than 17.03, how would one view the layers of an image? While I found tons of solutions for earlier Docker systems (see this SO question), can this still be done now?

I am particularly interested in being able to remove layers one at a time. I recall reading about this long ago (in Docker time, so that is about 12-18 months!) However, I lost that reference and can not find it anywhere on the web. I learned from the first answer below that the intermediate layers are no longer downloaded and report as missing, but if I have the entire image downloaded, is there a way to take it apart one layer at a time?

JoeG
  • 7,191
  • 10
  • 60
  • 105

1 Answers1

4

You mention "AUFS" but the issue unrelated to storage drivers.

Prior to v1.10.0, docker would download an image along with all of its intermediate layers. Using docker history <image_id> you could get the intermediate layer IDs. Then you could explore the /var/lib/docker/<storage_driver>/ directory to see the changes introduced by each intermediate layer, or you could even start a container from any one of them.

This is no longer the case according to https://github.com/moby/moby/issues/20131:

"...We don't pull parent images anymore. You only have them if you built the image yourself or if you migrated your old image chains."

Note that docker history now outputs <missing> instead of the image ID for each unavailable intermediate layer.

$ docker history ubuntu
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
ccc7a11d65b1        2 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B                  
<missing>           2 weeks ago         /bin/sh -c mkdir -p /run/systemd && echo '...   7B                  
<missing>           2 weeks ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\...   2.76kB              
<missing>           2 weeks ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          0B                  
<missing>           2 weeks ago         /bin/sh -c set -xe   && echo '#!/bin/sh' >...   745B                
<missing>           2 weeks ago         /bin/sh -c #(nop) ADD file:39d3593ea220e68...   120MB            

More information here: https://github.com/moby/moby/wiki/Engine-v1.10.0-content-addressability-migration

That being said, if you have access to the Dockerfile and the supporting resources that were used to build the image, you can build the image locally (which will save each intermediate layer)

Ubuntu publishes its Dockerfiles here: https://hub.docker.com/_/ubuntu/

So if you wanted to build a 17.10 image for examples you would:

  1. Create a build directory
  2. Copy the Dockerfile to the build directory.
  3. Copy supporting resources to the build directory
In this case the dockerfile contains the following command:
ADD ubuntu-artful-core-cloudimg-amd64-root.tar.gz /
You can find that file with a Google search 
Note: The ADD command automatically extracts and unzips recognized formats.
  1. cd to the build directory and run docker build .

If you don't have access to the Dockerfile, you can try to create one using the output of docker history --no-trunc <image_id>` you may run into a couple of issues:

  1. You may be missing the supporting resources
  2. Layers can be manual modified in which case the output of docker history would not tell you the full story
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
el_tigro
  • 1,099
  • 2
  • 10
  • 22