问题
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