gpt4 book ai didi

linux - 以前的 apt-get update & install Docker 层在每次构建期间都被删除

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:52 31 4
gpt4 key购买 nike

我有一个包含以下内容的 Dockerfile:

FROM ubuntu:17.10
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install -y \
python3-pip \
python3-numpy \
ffmpeg \
python3.6 \
xz-utils
...

每次运行docker build时,在RUN语句中创建的层都会被删除,我不确定为什么会出现这种情况。安装所有依赖项需要很长时间,因此我希望 Docker 缓存该层并在将来再次使用它。

我该怎么做才能获得这种行为?

谢谢。

最佳答案

根据 documentation ,如果一层的缓存失效,则需要重新构建后续层。因此,最佳实践是首先在 Dockerfile 中包含所有静态步骤(例如,在您的情况下,您可以将 RUN apt-get ... 命令向上移动)。希望清楚

For the ADD and COPY instructions, the contents of the file(s) in the image are examined and a checksum is calculated for each file. The last-modified and last-accessed times of the file(s) are not considered in these checksums. During the cache lookup, the checksum is compared against the checksum in the existing images. If anything has changed in the file(s), such as the contents and metadata, then the cache is invalidated.

Once the cache is invalidated, all subsequent Dockerfile commands will generate new images and the cache will not be used.

关于linux - 以前的 apt-get update & install Docker 层在每次构建期间都被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48029756/

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