@@ -500,10 +500,10 @@ Example (parsed representation is displayed after the `#`):
500500
501501``` dockerfile
502502FROM busybox
503- ENV foo /bar
504- WORKDIR ${foo } # WORKDIR /bar
505- ADD . $foo # ADD . /bar
506- COPY \$ foo /quux # COPY $foo /quux
503+ ENV FOO= /bar
504+ WORKDIR ${FOO } # WORKDIR /bar
505+ ADD . $FOO # ADD . /bar
506+ COPY \$ FOO /quux # COPY $FOO /quux
507507```
508508
509509Environment variables are supported by the following list of instructions in
@@ -994,53 +994,56 @@ port. For detailed information, see the
994994## ENV
995995
996996```dockerfile
997- ENV <key> <value>
998997ENV <key>=<value> ...
999998```
1000999
10011000The `ENV` instruction sets the environment variable `<key>` to the value
10021001`<value>`. This value will be in the environment for all subsequent instructions
10031002in the build stage and can be [replaced inline](#environment-replacement) in
1004- many as well.
1005-
1006- The `ENV` instruction has two forms. The first form, `ENV <key> <value>`,
1007- will set a single variable to a value. The entire string after the first
1008- space will be treated as the `<value>` - including whitespace characters. The
1009- value will be interpreted for other environment variables, so quote characters
1010- will be removed if they are not escaped.
1011-
1012- The second form, `ENV <key>=<value> ...`, allows for multiple variables to
1013- be set at one time. Notice that the second form uses the equals sign (=)
1014- in the syntax, while the first form does not. Like command line parsing,
1003+ many as well. The value will be interpreted for other environment variables, so
1004+ quote characters will be removed if they are not escaped. Like command line parsing,
10151005quotes and backslashes can be used to include spaces within values.
10161006
1017- For example :
1007+ Example :
10181008
10191009```dockerfile
1020- ENV myName=" John Doe" myDog=Rex\ The\ Dog \
1021- myCat=fluffy
1010+ ENV MY_NAME=" John Doe"
1011+ ENV MY_DOG=Rex\ The\ Dog
1012+ ENV MY_CAT=fluffy
10221013```
10231014
1024- and
1015+ The `ENV` instruction allows for multiple `<key>=<value> ...` variables to be set
1016+ at one time, and the example below will yield the same net results in the final
1017+ image:
10251018
10261019```dockerfile
1027- ENV myName John Doe
1028- ENV myDog Rex The Dog
1029- ENV myCat fluffy
1020+ ENV MY_NAME=" John Doe" MY_DOG=Rex\ The\ Dog \
1021+ MY_CAT=fluffy
10301022```
10311023
1032- will yield the same net results in the final image.
1033-
10341024The environment variables set using `ENV` will persist when a container is run
10351025from the resulting image. You can view the values using `docker inspect`, and
10361026change them using `docker run --env <key>=<value>`.
10371027
10381028> **Note**
10391029>
1040- > Environment persistence can cause unexpected side effects. For example,
1041- > setting `ENV DEBIAN_FRONTEND noninteractive` may confuse apt-get
1042- > users on a Debian-based image. To set a value for a single command, use
1043- > `RUN <key>=<value> <command>`.
1030+ > Environment variable persistence can cause unexpected side effects. For example,
1031+ > setting `ENV DEBIAN_FRONTEND=noninteractive` changes the behavior of `apt-get`,
1032+ > and may confuse users of your image.
1033+ >
1034+ > If an environment variable is only needed during build, and not in the final
1035+ > image, consider setting a value for a single command instead:
1036+ >
1037+ > ```dockerfile
1038+ > RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ...
1039+ > ```
1040+ >
1041+ > Or using [`ARG`](#arg), which is not persisted in the final image:
1042+ >
1043+ > ```dockerfile
1044+ > ARG DEBIAN_FRONTEND=noninteractive
1045+ > RUN apt-get update && apt-get install -y ...
1046+ > ```
10441047
10451048## ADD
10461049
@@ -1768,7 +1771,7 @@ The `WORKDIR` instruction can resolve environment variables previously set using
17681771For example:
17691772
17701773``` dockerfile
1771- ENV DIRPATH /path
1774+ ENV DIRPATH= /path
17721775WORKDIR $DIRPATH/$DIRNAME
17731776RUN pwd
17741777```
@@ -1873,7 +1876,7 @@ this Dockerfile with an `ENV` and `ARG` instruction.
18731876``` dockerfile
18741877FROM ubuntu
18751878ARG CONT_IMG_VER
1876- ENV CONT_IMG_VER v1.0.0
1879+ ENV CONT_IMG_VER= v1.0.0
18771880RUN echo $CONT_IMG_VER
18781881```
18791882
@@ -1894,7 +1897,7 @@ useful interactions between `ARG` and `ENV` instructions:
18941897``` dockerfile
18951898FROM ubuntu
18961899ARG CONT_IMG_VER
1897- ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0}
1900+ ENV CONT_IMG_VER= ${CONT_IMG_VER:-v1.0.0}
18981901RUN echo $CONT_IMG_VER
18991902```
19001903
@@ -2030,7 +2033,7 @@ Consider another example under the same command line:
20302033``` dockerfile
20312034FROM ubuntu
20322035ARG CONT_IMG_VER
2033- ENV CONT_IMG_VER $CONT_IMG_VER
2036+ ENV CONT_IMG_VER= $CONT_IMG_VER
20342037RUN echo $CONT_IMG_VER
20352038```
20362039
@@ -2045,7 +2048,7 @@ this Dockerfile:
20452048``` dockerfile
20462049FROM ubuntu
20472050ARG CONT_IMG_VER
2048- ENV CONT_IMG_VER hello
2051+ ENV CONT_IMG_VER= hello
20492052RUN echo $CONT_IMG_VER
20502053```
20512054
0 commit comments