知识卡片
依赖先于源码构建镜像
Dockerfile 先复制锁定依赖的文件并安装依赖,后复制频繁变动的应用代码,可复用前面未失效的构建缓存层,减少反复安装。复制顺序服务于变更频率;依赖或上游步骤变化时仍须重建后续层。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 13 章《Dockerizing microservice APIs》(源文件:_epub-src/OEBPS/Text/13.htm)
- 结论依据:原文明确说缓存按步骤失效,依赖文件先复制、源码最后复制可减少依赖重复安装。
- 原始内容:The order of our statements in the Dockerfile matters because Docker caches each step of the build. Docker will only execute a step again if the previous step changed, for example, if we installed a new dependency, or