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?

  • Run LiveServerTestCase from Docker Selenium with Django 1.11
  • {“message”:“No such image: jenkins_slave_1:latest”}
  • how to bind ports with docker-py
  • Can several nodes access mounted docker containers
  • How can I run `gcloud preview app setup-managed-vms` without this error?
  • Unable to load balance using Docker, Consul and nginx
  • Merging files tree with parent Docker image
  • Oracle database on VirtualBox VM or Docker?
  • Running commands inside Docker Container
  • Travis Docker Image missing Python 3.5
  • How can I create a docker volume container in specific directory?
  • Overriding image version in docker-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.