英文:
Will apt update run every time in my docker build?
问题
I have a dockerfile and its fifth line is
RUN apt update -y
Suppose those first five lines will not change in future builds. Only lines below will change.
Question
When I build this image later again and again,
- Will the
apt update
run again (so producing changing versions of packages, ending with an undeterministic result) or... - Thanks to the layered filesystem changes, up to the layer created after this line it will be reused from the cache?
英文:
I have a dockerfile and its fifth line is
RUN apt update -y
Suppose those first five lines will not change in future builds. Only lines below will change.
Question
When I build this image later again and again,
- Will the
apt update
run again (so producing changing versions of packages, ending with an undeterministic result) or... - Thanks to the layered filesystem changes, up to the layer created after this line it will be reused from the cache?
答案1
得分: 3
由“RUN apt update -y”命令生成的层已被缓存,除非缓存无效,否则该命令不会再次运行,缓存可能以多种不同的方式无效:
- 您可以通过使用“--no-cache”选项来显式禁用缓存。
- 您修改了位于“apt update”命令之前的Dockerfile的部分。
- 您更新了基础镜像(例如通过“docker pull”或“docker build --pull”)。
- 您的“Dockerfile”将一个文件复制到镜像中,该文件自上次构建镜像以来发生了更改。
英文:
The layer generated by the RUN apt update -y
command is cached and the command will not run again unless the cache is invalidated, which can happen in a number of different ways:
- You explicitly disable the cache by using the
--no-cache
option. - You modify parts of your Dockerfile that precede the
apt update
line. - You update the base image (e.g. via
docker pull
ordocker build --pull
). - Your
Dockerfile
copies a file into the image that has changed since the last time the image was built.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论