Accepted answer does not cover "if else condition" part of the question. Would be better to rename it to "Dockerfile with external arguments" if condition check didn't mean to be a requirement.
The difference between Dockerfile and Compose file Docker can build images automatically by reading the instructions from a Dockerfile Compose is a tool for defining and running multi-container Docker applications The main difference is Dockerfile is used to build an image while Compose is to build and run an application.
This command is specified in the Dockerfile using the CMD instruction. For example, if you have a Dockerfile with CMD ["echo", "Hello Docker"], when you run the Docker container without specifying a command, it will execute echo "Hello Docker".
I'm trying to set environment variables in docker container during the build but without success. Setting them when using run command works but I need to set them during the build. Dockerfile FROM ...
dockerfile - How do I set environment variables during the "docker ...
Tagging of the image isn't supported inside the Dockerfile. This needs to be done in your build command. However there are multiple ways to build an image. docker-compose.yml You can do the build with a docker-compose.yml file that identifies the image name and then run a docker-compose build. A sample docker-compose.yml file would look like:
How can I set an image name in a Dockerfile? - Stack Overflow
How can I generate a Dockerfile from an image? - Stack Overflow