fig*_*ter 4 cloud containers docker dockerfile
我在下面的 Dockerfile 中编写了一些 shell 代码来检查容器中的某些目录,如果容器中没有那些我想停止构建的文件夹。那么我应该在 Dockerfile 中编写什么来停止它呢?
FROM XXX
...
RUN if [ -d "/app/bin" -a -d "/app/lib" -a -d "/app/conf" -a -d "/app/resource" -a -d "/app/log" -a -f "/app/bin/start.sh" ]; then mkdir -p /app/control/bin; else SOME_CODES_TO_STOP_BUILDING; fi
...
Run Code Online (Sandbox Code Playgroud)
任何失败的 shell 命令(返回除 0 之外的退出状态)都将停止构建。一些例子:
# Probably the most idiomatic shell scripting: if the test
# returns false, then the "&&" won't run mkdir, and the whole
# command returns false
RUN test -d /app/bin -a ... \
&& mkdir /app/control/bin
# "test" and "[" are the same thing
RUN [ -d /app/bin -a ... ] \
&& mkdir /app/control/bin
# This first step will just blow up the build if it fails
RUN [ -d /app/bin -a ... ]
# Then do the on-success command
RUN mkdir /app/control/bin
# Your original suggestion
# /bin/false does nothing but returns 1
RUN if [ -d /app/bin -a ... ]; \
then mkdir /app/control/bin; \
else false; \
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10762 次 |
| 最近记录: |