从另一个Dockerfile运行命令(但不是在开头;没有“from”)

从另一个Dockerfile运行命令(但不是在开头;没有“from”),docker,dockerfile,Docker,Dockerfile,目前,我正在维护3个dockerfile(test、dev、prod),它们基本相同 意译: #Dockerfile.dev FROM <blah> # Necessitates rebuild of the below commands, so I want it at the top COPY <Content which is unique within dev, prod, test RUN <Lots of commands which are id

目前,我正在维护3个dockerfile(test、dev、prod),它们基本相同

意译:

#Dockerfile.dev 

FROM <blah>

# Necessitates rebuild of the below commands, so I want it at the top 
COPY <Content which is unique within dev, prod, test 

RUN <Lots of commands which are identical between dev, prod, test> 

EXPOSE <blah>

CMD <Commands which are divergent in dev, prod, test>
#Dockerfile.dev
从…起
#需要重建以下命令,所以我希望它位于顶部

复制检查ARG:尤其是
--build ARG
partAhhh,我知道ARG,但没想到会这样使用它。如果我的顶层(dev/prod/test中的不同部分)包含不同的命令(取决于构建),这是否可行?例如,如果dev包含RUN、COPY、RUN,但是prod只包含一个RUN,那么我可以参数化多行吗?除非您需要
将构建上下文中的内容复制到容器中,否则您可以只运行脚本<代码>运行$SCRIPT
。使用
ARG
时,可以定义一个默认值,使其成为可选值。(可以是好的也可以是坏的!)