Dockerfile中的条件ARG? [英] Conditional ARG in Dockerfile?
本文介绍了Dockerfile中的条件ARG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我通过可选的ARG,我试图有条件地在我的docker容器中安装vim-像DEVBUILD这样的东西.我找不到任何有关如何在Dockerfile中使用IF之类的文档.像这样:
I'm trying to conditionally install vim in my docker container if I pass an optional ARG - say something like DEVBUILD. I can't find any documentation on how to use something like IF in a Dockerfile. Something like this:
FROM node:8
if $DEVBUILD {
RUN apt-get update
RUN apt-get --assume-yes install vim
}
是否可能?如果可以,在哪里可以找到语法参考?
Is this possible, and if so, where can find a reference on the syntax?
推荐答案
是的,有可能.docker构建映像时,它使用标准外壳.
Yes, it is possible. When docker builds image it uses standard shell.
Dockerfile
是:
FROM node:8
ARG DEVBUILD
RUN if [ "x$DEVBUILD" != "x" ]; then apt-get update && apt-get --assume-yes install vim; fi
如果您定义变量 DEVBUILD
,例如 DEVBUILD = true
:
If you define variable DEVBUILD
like, for example, DEVBUILD=true
:
docker build . --no-cache --build-arg DEVBUILD=true
if语句下的动作将被执行.
actions under if statement will be executed.
这篇关于Dockerfile中的条件ARG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文