← 返回刚才阅读的位置

知识卡片

操作参考卡 · 4545.g.9

多阶段构建分离工具与制品

理解等级:中级

先在带编译工具的阶段构建二进制,再把所需产物复制到运行阶段,可把编译环境与最终镜像分开。scratch没有常规发行版文件,要求二进制目标平台、链接方式及运行资料齐备。原书Go1.15命令和镜像大小属于历史示例;版本、依赖与架构应在实际构建中明确固定和核验。

构建形式为FROM golang:1.15 AS build后接运行阶段COPY --from=build ...;此为原稿历史语法示意,不是当前版本推荐或完整Dockerfile。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Building a Cloud Native Service · 查看原书依据

      A better solution became available with the introduction of multi-stage Docker builds, which allow multiple distinct builds — even with entirely different base images — to be chained together so that artifacts in one stage can be selectively copied into another, leaving behind everything we don’t want in the final image. Using this approach we

    参考来源

    - 位置:《Cloud Native Go》第05章《Building a Cloud Native Service》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch05.xhtml) - 结论依据:先在带编译工具的阶段构建二进制,再把所需产物复制到运行阶段,可把编译环境与最终镜像分开。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:A better solution became available with the introduction of multi-stage Docker builds, which allow multiple distinct builds — even with entirely different base images — to be chained together so that artifacts in one stage can be selectively copied into another, leaving behind everything we don’t want in the final image. Using this approach we