我有一个Dockerfile:
FROM python:2
# Large number of commands我想要创建Dockerfile-py3,它扩展了python:3而不是python:2,但在其他方面是相同的。除了
FROM python:3
# Copy of large number of commands为了避免冗余,我有什么解决方案?
发布于 2018-06-25 08:19:29
您可以使用build-arg选项将docker build与Dockerfile的ARG和FROM指令一起使用,以获得如下所需的结果:
Dockerfile实例
ARG  REPOSITORY_AND_TAG=python:2.7
FROM ${REPOSITORY_AND_TAG}
# Large number of commands   现在,如果构建时没有任何build-arg,它将默认为python:2.7,就像在Dockerfile中声明的那样。但是,如果使用build-arg构建,您可以选择如下所示的替代值:
docker build --build-arg REPOSITORY_AND_TAG=python:latest -t my-docker-image .在这种情况下,它将覆盖来自Dockerfile的默认值(Dockerfile),您最终将得到python:latest。
补充文件:
ARG在FROM指令中的用法,可以在正式Dockerfile引用中找到build-arg使用也来自正式文件https://stackoverflow.com/questions/51018598
复制相似问题