Table of Contents

Dockerfile - Variable / env

About

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

Unlike an ARG instruction, ENV values are always persisted in the built image.

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:

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.