Conditional ARG in Dockerfile?

心已入冬 提交于 2021-02-08 10:33:50

问题


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?


回答1:


Yes, it is possible. When docker builds image it uses standard shell.

Dockerfile is:

FROM node:8
ARG DEVBUILD
RUN if [ "x$DEVBUILD" != "x" ]; then apt-get update && apt-get --assume-yes install vim; fi

If you define variable DEVBUILD like, for example, DEVBUILD=true:

docker build . --no-cache --build-arg DEVBUILD=true

actions under if statement will be executed.



来源:https://stackoverflow.com/questions/48775351/conditional-arg-in-dockerfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!