Docker - Dockerfile env

Card Puncher Data Processing


This page talks about OS/Shell Environment variable in dockerfile.




ENV <key> <value>
ENV <key>=<value>

# example
ENV myName John Doe
ENV myDog Rex The Dog
ENV myCat fluffy


docker run --env <key>=<value>

Expansion (Replacement)

Docker variable expansion works the same than variable 2)

Environment variables are notated

#or the brace syntax is typically used to address issues with variable names with no whitespace, like ${foo}_bar.

The variable_name syntax also supports a few of the standard bash modifiers as specified below:

  • variable:-word indicates that if variable is set then the result will be that value. If variable is not set then word will be the result.
  • variable:+word indicates that if variable is set then word will be the result, otherwise the result is the empty string.

In all cases, word can be any string, including additional environment variables.

Escaping is possible by adding a \ before the variable: \foo or \foo, for example, will translate to foo and foo literals respectively.

Share this page:
Follow us:
Task Runner