ENV <key> <value>
ENV <key>=<value> ...
The ENV
instruction sets the environment variable <key>
to the value . This value will be in the environment of all “descendant” Dockerfile commands and can be replaced inline in many as well.
The ENV
instruction has two forms. The first form, ENV <key> <value>
, will set a single variable to a value. The entire string after the first space will be treated as the <value>
- including characters such as spaces and quotes.
The second form, ENV <key>=<value> ...
, allows for multiple variables to be set at one time. Notice that the second form uses the equals sign (=) in the syntax, while the first form does not. Like command line parsing, quotes and backslashes can be used to include spaces within values.
For example:
ENV myName="John Doe" myDog=Rex\ The\ Dog \
myCat=fluffy
and
ENV myName John Doe
ENV myDog Rex The Dog
ENV myCat fluffy
will yield the same net results in the final container, but the first form is preferred because it produces a single cache layer.
The environment variables set using ENV
will persist when a container is run from the resulting image. You can view the values using docker inspect, and change them using docker run --env <key>=<value>
.
If you don't wish to persist the setting, use ARG
instead. ARG
will set environments only during the build. For example, setting
ENV DEBIAN_FRONTEND noninteractive
may confuse apt-get
users on a Debian-based image when they enter the container in an interactive context via docker exec -it the-container bash
.
Instead, use:
ARG DEBIAN_FRONTEND noninteractive
You might alternativly also set a value for a single command only by using:
RUN <key>=<value> <command>