知识卡片

普通读书笔记卡 · 3522.a

依赖先于源码构建镜像

理解等级:中级

Dockerfile 先复制锁定依赖的文件并安装依赖,后复制频繁变动的应用代码,可复用前面未失效的构建缓存层,减少反复安装。复制顺序服务于变更频率;依赖或上游步骤变化时仍须重建后续层。

这张卡片看不懂?

已有反馈 · 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