Dockerfile if else condition with external arguments

What is the problem ?

I have dockerfile

then I build it

and run it.

Is it possible to pass arguments from command line and use it with if else in Dockerfile? I mean something like

and build with this argument.

The best solution for the above problem is…

It might not look that clean but you can have your Dockerfile (conditional) as follow:

and then build the image as:

docker build -t my_docker . --build-arg arg=45

or

docker build -t my_docker .

Know more solutions for the same problem with different ways are here SyntaxFix

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SyntaxFix

SyntaxFix

Curated Solutions On Popular Questions — On All Programming Languages, Cloud Computing, Tools etc