`apt update`会在我的Docker构建中每次运行吗?

huangapple go评论57阅读模式
英文:

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 or docker build --pull).
  • Your Dockerfile copies a file into the image that has changed since the last time the image was built.

huangapple
  • 本文由 发表于 2023年5月18日 11:19:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定