Passing variables as arguments to docker container
I want to be able to declare a variable in dockerfile and pass it as an argument when container runs for user to provide. The variable is actually a git hub URL that needs to be cloned in the container.
So far I thought about declaring a ENV variable and passing it using -e in run command. How else can I pass a variable to the docker run command?
One Solution collect form web for “Passing variables as arguments to docker container”
There is nothing wrong with passing configuration through the environment (that’s how you’re supposed to use Docker).
However, depending on what you’re trying to achieve, it might be more relevant to actually build the container image ahead of time, and include the cloned repository in there.
You could actually have multiple Dockerfiles:
- One that creates the “base” image (which you’re building right now),
- Multiple ones that just clone the repository you need (i.e. doing it at build-time instead of runtime)