是否可以在Docker映像中标记上一层或还原提交? [英] Is there a way to tag a previous layer in a docker image or revert a commit?

查看:95
本文介绍了是否可以在Docker映像中标记上一层或还原提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个docker映像,有人对其进行了更改,然后将其推送到docker存储库中。然后,我拉下图像。有没有办法获取该图像并运行上一层的容器?

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.

如果我运行docker history,它将看起来像这样:

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.

推荐答案

如果有访问权限,可以通过标记图像的构建层来进行标记或识别。给他们。如此处所述。

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

在您的案例可能发生的情况是,从v1.10.0版开始,他们已经更改了 docker引擎处理内容寻址能力。正在此处进行大量讨论。

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

这应该收集给定图像的所有构建层并将其保存到缓存tar文件。

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

这篇关于是否可以在Docker映像中标记上一层或还原提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆