Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change base image based on condition in dockerfile

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.

like image 285
Nagasitaram Thigulla Avatar asked Nov 01 '25 18:11

Nagasitaram Thigulla


1 Answers

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 .
like image 184
mchawre Avatar answered Nov 04 '25 09:11

mchawre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!