Creating Dockerfile with Environmental Variables

I’m trying to create a docker image that will run a command for the users. The command will need a number of variable entries, specific for the person running it. I tried simply creating it with the variables and, because the command couldn’t be run upon build, the process wouldn’t complete. I then tried using the ‘${varname:-possible value}, and I got a little further.

I’m guessing part of the problem may be that some of the variables are URLs, since the folder name, also a variable, is being accepted. I did try adding escape characters (‘\’) to all the special characters in the URL and all that did was get me a ‘bad substitution’ error instead.

  • WSO2 version 2 docker files
  • Within Docker VM, Gulp-Watch Seems to not work well on volumes hosted from the host OS
  • Jenkins Docker Plugin does not seem to be provisioning slave containers for Jenkins builds
  • docker stack with overlay network & name resolution
  • Nginx and uwsgi connection refused when placed in separate docker containers
  • docker compose file not working: replicas Additional property replicas is not allowed
  • What then, should I change in my syntax?

    RUN /usr/bin/java -jar export.jar calendar \
        --output /var/www \
        --format public \
        --restUri ${one_uri:-} \
        --daysForward ${days_forward:-30}

  • Can we pass ENV variables through cmd line while building a docker image through dockerfile?
  • Run apache/php/nginx in background Docker container
  • Creating Docker Base Image from a Dockerfile?
  • Jenkinsfile custom docker container “could not find FROM instruction”
  • Empty project with docker supper in Visual Studio
  • Can't remove or stop a container
  • One Solution collect form web for “Creating Dockerfile with Environmental Variables”

    I don’t exactly get if your users is building their own Dockerfile or they are using your docker image directly, but if they create their own, then you can use ONBUILD to run a command that will when the user docker build their container.


    you can just specify your own defaults like this

    ENV days_forward "30"

    and then they can easily overwrite that environment variable when they run your container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.