Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tag a previous layer in a docker image or revert a commit?

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.

like image 756
jchysk Avatar asked Jul 06 '16 22:07

jchysk


1 Answers

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.

like image 196
Rogério Peixoto Avatar answered Oct 23 '22 03:10

Rogério Peixoto