4

I want to send an argument USE_ALPINE to docker file if it is true i will use alpine image if it is false i will use debian image

the default value for USE_ALPINE i want to set it to false.

mchawre
  • 10,744
  • 4
  • 35
  • 57

1 Answers1

6

Make use of combination of ARG and FROM in Dockerfile.

You can use variables declared in ARG inside FROM statement.

ARG  APP_IMAGE=alpine:latest
FROM ${APP_IMAGE}
CMD  /path/to/mycode

And can also override this value using --build-arg option of docker build command.

docker build -t myapp:v1 --build-arg APP_IMAGE=busybox:latest .
mchawre
  • 10,744
  • 4
  • 35
  • 57
  • 1
    but the requirement is to use a boolean do we have any possibility to do so? – Nagasitaram Thigulla Jan 20 '21 at 04:32
  • Can;t find any in-built support for boolean flag in docker build. But you can try something with combination of multi-stage builds and arguments. Check this https://stackoverflow.com/a/60820156 – mchawre Jan 20 '21 at 08:03