Docker - Dockerfile env

Card Puncher Data Processing

About

This page talks about Environment variable in dockerfile.

Management

Define

1)

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

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

Set

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

Expansion (Replacement)

Docker variable expansion works the same than variable 2)

Environment variables are notated

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

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