gpt4 book ai didi

docker - 为什么要使用 docker ONBUILD?

转载 作者:行者123 更新时间:2023-12-02 19:20:25 25 4
gpt4 key购买 nike

1。 with ONBUILD

场景

基础 Dockerfile

FROM ubuntu:latest
RUN apt-get update && apt-get install python3

ONBUILD COPY test.py test.py

显然,当我们在 Dockerfile(test-image:latest) 之上构建时,COPY 不会受到影响。(测试.py 未复制)

现在构建Dockerfile

FROM test-image:latest

现在,当我们在 Dockerfile 上构建时,COPY 会影响,复制 test.py

2。没有 ONBUILD

的场景

我在不使用 ONBUILD

的情况下实现了同样的效果

基础 Dockerfile

FROM ubuntu:latest
RUN apt-get update && apt-get install python3

Dockerfile 之上构建包含 python3 (test-image2:latest)

的 docker 镜像

现在子docker镜像Dockerfile

FROM test-image2:latest
COPY test.py /test.py

那么,我的问题是,为什么要使用ONBUILD 或什么时候应该使用?有什么性能差异

最佳答案

我认为答案很简单:当您的父图像必须用于各种子图像时,您想使用 ONBUILD,所以您

  1. 避免重复
  2. contstrain 图像的用户复制 test.py

关于docker - 为什么要使用 docker ONBUILD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com