我有一个Dockerfile,我想根据build参数做不同的事情来确定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
我在做什么错了?
答案 0 :(得分:2)
您不会喜欢这个答案,[
之后缺少空格。在右括号之前,您需要另一个空格,并且需要对换行符进行转义。至少我是第一眼看到的。
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if [ "${isDev}" = "1" ] ; \
then ..... do dev stuff .... ; \
else .... do production stuff ; \
fi