Dockerfile 中的条件 ARG
Conditional ARG in Dockerfile
我有一个 Dockerfile,我想根据构建参数执行不同的操作以确定是否为 isDev。
在 Dockerfile 中,我有:
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if ["${isDev}" = "1"] ;
then ..... do dev stuff .... ;
else .... do production stuff ;
fi
我正在使用我的 --build-arg isDev=1
进行构建
Step 14/25 : ARG isDev
---> Running in 0a3de5fea466
Removing intermediate container 0a3de5fea466
---> a6d79a08a97e
Step 15/25 : RUN echo "what is in isDev ? $isDev"
---> Running in 92235e8b0c6a
what is in isDev ? 1
Removing intermediate container 92235e8b0c6a
---> a7b064687480
Step 16/25 : RUN if ["${isDev}" = "1"] ; then ... do dev stuff ... ; else ... do production stuff ... ; fi
---> Running in bbe6a047705a
[91m/bin/sh: 1: [1: not found
我做错了什么?
您不会喜欢这个答案,您在 [
之后缺少 space。在右括号之前您需要另一个 space ,并且您需要转义换行符。至少那是我第一眼看到的。
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if [ "${isDev}" = "1" ] ; \
then ..... do dev stuff .... ; \
else .... do production stuff ; \
fi
我有一个 Dockerfile,我想根据构建参数执行不同的操作以确定是否为 isDev。
在 Dockerfile 中,我有:
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if ["${isDev}" = "1"] ;
then ..... do dev stuff .... ;
else .... do production stuff ;
fi
我正在使用我的 --build-arg isDev=1
进行构建Step 14/25 : ARG isDev
---> Running in 0a3de5fea466
Removing intermediate container 0a3de5fea466
---> a6d79a08a97e
Step 15/25 : RUN echo "what is in isDev ? $isDev"
---> Running in 92235e8b0c6a
what is in isDev ? 1
Removing intermediate container 92235e8b0c6a
---> a7b064687480
Step 16/25 : RUN if ["${isDev}" = "1"] ; then ... do dev stuff ... ; else ... do production stuff ... ; fi
---> Running in bbe6a047705a
[91m/bin/sh: 1: [1: not found
我做错了什么?
您不会喜欢这个答案,您在 [
之后缺少 space。在右括号之前您需要另一个 space ,并且您需要转义换行符。至少那是我第一眼看到的。
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if [ "${isDev}" = "1" ] ; \
then ..... do dev stuff .... ; \
else .... do production stuff ; \
fi