8

Let's say there is a docker image, someone makes changes to it and then pushes it up to a docker repository. I then pull down the image. Is there a way to then take that image and run a container from a previous layer? Run the version before the changes were made.

If I run docker history it will look something like this:

docker history imagename:tag
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
3e23a5875458        8 days ago          /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8            0 B
<missing>           8 days ago          /bin/sh -c dpkg-reconfigure locales &&    loc   1.245 MB
<missing>           8 days ago          /bin/sh -c apt-get update && apt-get install    338.3 MB
<missing>           6 weeks ago         /bin/sh -c #(nop) ADD jessie.tar.xz in /        121 MB
<missing>           6 weeks ago         /bin/sh -c #(nop) MAINTAINER ssss <ad   0 B
<missing>           9 months ago                                                        0 B   

It seems as if I could run an earlier version if I figure out a way to somehow tag or identify previous layers of the image.

jchysk
  • 1,538
  • 1
  • 15
  • 27

1 Answers1

8

You can, by tagging build layers of the image if you have access to them. As described here.

In your case what could be happening is that from version v1.10.0 forward they've changed the way that the docker engine handles content addressability. This is being heavily discussed here.

What it means is that you won't have access to the build layers unless you built this image in the current machine or exported and loaded by combining:

docker save imagename build-layer1 build-layer2 build-layer3 > image-caching.tar
docker load -i image-caching.tar

A user has posted a handy way to save that cache in the discussion I've mentioned previously:

docker save imagename $(sudo docker history -q imagename | tail -n +2 | grep -v \<missing\> | tr '\n' ' ') > image-caching.tar

This should collect all the build layers of the given image and save them to a cache tar file.

Rogério Peixoto
  • 2,176
  • 2
  • 23
  • 31
  • 2
    Basically, for v1.10.0 and forward you cannot tag previous layers from an image's history unless the build cache is available. – jchysk Jul 07 '16 at 02:26
  • Could you explain what you mean by build-layer1 build-layer2 buld-layer3 here? I don't have anything I can substitute. – meesern Oct 13 '20 at 12:08