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?

  • Docker-compose: ERR_EMPTY_RESPONSE
  • How to disable Nginx caching when running Nginx using Docker
  • Docker LAMP Stack
  • invalid argument creating a ruby dev env with docker & fig
  • Docker doesn't install correct on Mac
  • Can ping intranet from host, but not from a container
  • Docker image wrapping for binary blobs
  • Sending Multicast Packets from Docker Container (to multicast group)
  • Execute script inside docker container which is folder different than WORKDIR
  • Install Docker in Ubuntu 14.04
  • How can I test that a docker wordpress-fpm with custom plugins works
  • Clarification on Maven profiles and Phases
  • 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.