Docker摘要应该是不可变的,但是要获得不同的构建步骤

问题描述 投票:0回答:1

回到1月份,我使用“FROM node:10.12.0”构建了我的应用程序版本。

信号量构建过程日志显示:

d8268e1e433b: Pull complete 
Digest: sha256:00a7fb3df8e94ed24f42c2920f132f06e92ea5ed69b1c5e53c4bb3d20e85a3e2
Status: Downloaded newer image for node:10.12.0
 ---> a2b9536415c2
Step 2/11 : RUN apt-get update
 ---> Running in f9bd6b252e7f
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [790 kB]
Get:4 http://deb.debian.org jessie Release.gpg [2420 B]
Get:5 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:6 http://deb.debian.org jessie Release [148 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 10.3 MB in 2s (3476 kB/s)
Reading package lists...

刚才我试图建立一个新版本。我没有碰过这些构建文件或自1月以来构建。我认为一切都应该有效。但我得到了这个:

d8268e1e433b: Pull complete 
Digest: sha256:00a7fb3df8e94ed24f42c2920f132f06e92ea5ed69b1c5e53c4bb3d20e85a3e2
Status: Downloaded newer image for node:10.12.0
 ---> a2b9536415c2
Step 2/11 : RUN apt-get update
 ---> Running in e903db31c4a6
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [7340 B]
Get:3 http://deb.debian.org jessie Release.gpg [2420 B]
Get:4 http://deb.debian.org jessie Release [148 kB]
Get:5 http://security.debian.org jessie/updates/main amd64 Packages [825 kB]
Get:6 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 10.1 MB in 4s (2509 kB/s)
W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/InRelease  Unable to find expected entry 'main/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100

所以我发现了Docker Digests。应该能够使用Digest拥有纯粹的不可变构建。但是......这两个版本的摘要是一样的!

我是否正确地认为在'FROM'语句中使用摘要对我没有帮助?

这两个不同的版本怎么能有相同的摘要?

docker build immutability digest
1个回答
1
投票

你是正确的,你在上面构建的图像与之前相同,因为摘要匹配。问题是,这并不意味着Dockerfile中的后续指令每次都会以完全相同的方式运行。在这种情况下,当你打电话给apt-get update时,你正在接触远程的apt repos。我对这个过程并不特别了解,但基本上看起来有一些更新破坏了与这个图像的兼容性。每当你有这样的远程依赖(apt-get调用,下载文件等)时,它们可能会改变或变得不可用,导致你的构建失败,即使底层图像是相同的。

例如,如果我有这个Dockerfile

    FROM ubuntu:latest
    RUN curl http://some.url --output some.file

每次运行构建时,除非我将图层缓存,否则http://some.url需要可用,否则即使底层的ubuntu图像相同,构建也会失败。

© www.soinside.com 2019 - 2024. All rights reserved.