@@ -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,74 @@ 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
1038- > **Note**
1028+ Environment variable persistence can cause unexpected side effects. For example,
1029+ setting `ENV DEBIAN_FRONTEND=noninteractive` changes the behavior of `apt-get`,
1030+ and may confuse users of your image.
1031+
1032+ If an environment variable is only needed during build, and not in the final
1033+ image, consider setting a value for a single command instead:
1034+
1035+ ```dockerfile
1036+ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ...
1037+ ```
1038+
1039+ Or using [`ARG`](#arg), which is not persisted in the final image:
1040+
1041+ ```dockerfile
1042+ ARG DEBIAN_FRONTEND=noninteractive
1043+ RUN apt-get update && apt-get install -y ...
1044+ ```
1045+
1046+ > **Alternative syntax**
10391047>
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>`.
1048+ > The `ENV` instruction also allows an alternative syntax `ENV <key> <value>`,
1049+ > omitting the `=`. For example:
1050+ >
1051+ > ```dockerfile
1052+ > ENV MY_VAR my-value
1053+ > ```
1054+ >
1055+ > This syntax does not allow for multiple environment-variables to be set in a
1056+ > single `ENV` instruction, and can be confusing. For example, the following
1057+ > sets a single environment variable (`ONE`) with value `" TWO= THREE=world"`:
1058+ >
1059+ > ```dockerfile
1060+ > ENV ONE TWO= THREE=world
1061+ > ```
1062+ >
1063+ > The alternative syntax is supported for backward compatibility, but discouraged
1064+ > for the reasons outlined above, and may be removed in a future release.
10441065
10451066## ADD
10461067
@@ -1768,7 +1789,7 @@ The `WORKDIR` instruction can resolve environment variables previously set using
17681789For example:
17691790
17701791``` dockerfile
1771- ENV DIRPATH /path
1792+ ENV DIRPATH= /path
17721793WORKDIR $DIRPATH/$DIRNAME
17731794RUN pwd
17741795```
@@ -1873,7 +1894,7 @@ this Dockerfile with an `ENV` and `ARG` instruction.
18731894``` dockerfile
18741895FROM ubuntu
18751896ARG CONT_IMG_VER
1876- ENV CONT_IMG_VER v1.0.0
1897+ ENV CONT_IMG_VER= v1.0.0
18771898RUN echo $CONT_IMG_VER
18781899```
18791900
@@ -1894,7 +1915,7 @@ useful interactions between `ARG` and `ENV` instructions:
18941915``` dockerfile
18951916FROM ubuntu
18961917ARG CONT_IMG_VER
1897- ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0}
1918+ ENV CONT_IMG_VER= ${CONT_IMG_VER:-v1.0.0}
18981919RUN echo $CONT_IMG_VER
18991920```
19001921
@@ -2030,7 +2051,7 @@ Consider another example under the same command line:
20302051``` dockerfile
20312052FROM ubuntu
20322053ARG CONT_IMG_VER
2033- ENV CONT_IMG_VER $CONT_IMG_VER
2054+ ENV CONT_IMG_VER= $CONT_IMG_VER
20342055RUN echo $CONT_IMG_VER
20352056```
20362057
@@ -2045,7 +2066,7 @@ this Dockerfile:
20452066``` dockerfile
20462067FROM ubuntu
20472068ARG CONT_IMG_VER
2048- ENV CONT_IMG_VER hello
2069+ ENV CONT_IMG_VER= hello
20492070RUN echo $CONT_IMG_VER
20502071```
20512072
0 commit comments