gpt4 book ai didi

docker - 多阶段docker镜像是否具有相同的层?

转载 作者:行者123 更新时间:2023-12-02 18:52:49 24 4
gpt4 key购买 nike

假设我决定进行以下多阶段构建:

FROM node:8.6-alpine AS build1
#some other commands
FROM node:8.5-alpine AS build2
# yet another commands

肯定在build1和build2之间会有一些相同的层。 docker 会复制图层,还是以某种方式附加引用已构建的图层?

最佳答案

接下来是在新机器上构建dockerfile的结果:

# docker build -t test:1 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM node:8.6-alpine AS build1
8.6-alpine: Pulling from library/node
88286f41530e: Pull complete
d0e8a23136b3: Pull complete
5ad5b12a980e: Pull complete
Digest: sha256:60cd58a7a2bd9fec161f53f8886e451f92db06b91f4f72d9188eeea040d195eb
Status: Downloaded newer image for node:8.6-alpine
---> b7e15c83cdaf
Step 2/2 : FROM node:8.5-alpine AS build2
8.5-alpine: Pulling from library/node
88286f41530e: Already exists
aa0be12c5610: Pull complete
719d346e6de2: Pull complete
Digest: sha256:945cf56668d3e58a3b045291564963ccde29a68da9c1483e19d8a0b06749db06
Status: Downloaded newer image for node:8.5-alpine
---> 7a779c246a41
Successfully built 7a779c246a41
Successfully tagged test:1

从输出中,您可以看到图像ID 88286f41530e被重新用作 Already exists

docker images输出:
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
node 8.6-alpine b7e15c83cdaf 13 months ago 67.2MB
node 8.5-alpine 7a779c246a41 14 months ago 67MB

因此,multibuild中第一阶段的基础镜像也保留在缓存中。

从这个 post:

Since Docker v1.10, generally, images and layers are no longer synonymous. Instead, an image directly references one or more layers that eventually contribute to a derived container's filesystem.



因此,随着某些图像的重用,这些图层肯定会被重用。

当然,这取决于您在multibuild中使用的基础镜像,它们需要重用。

无论如何,我认为与传统构建相比,multibuild只是增加了一些技巧,但是层重用机制是相同的。

关于docker - 多阶段docker镜像是否具有相同的层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53276123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com