我有一个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
我究竟做错了什么?
最佳答案
您不会喜欢这个答案,在[
之后缺少空格。在右括号之前,您将需要另一个空格,并且需要对换行符进行转义。至少这是我乍看之下的内容。
ARG isDev
RUN echo "what is in isDev ? $isDev"
RUN if [ "${isDev}" = "1" ] ; \
then ..... do dev stuff .... ; \
else .... do production stuff ; \
fi