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?

  • make not found with Dockerfile and centos:7 image
  • What's the best way to share files from Windows to Boot2docker VM
  • how to enable docker remote api on windows-10
  • Private docker registry and high availability
  • Dockerized nodes of elasticsearch cluster in EC2, production environment
  • Docker returning same kernel version for 10.04 and 10.10
  • find docker containers created using a docker image
  • What are the best practices to manage and move Docker containers?
  • flocker-docker-plugin doesn't work
  • Cloudbees Docker Plugin - “?” Folder
  • fabric8io docker-maven-plugin in Windows
  • docker stack deploy do not remove services that are not declared in the current yaml compose file
  • 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)
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.