Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit fb91a7f

Browse files
committed
builder: rephrase ENV section, remove examples for ENV key value without '='
The `ENV key value` form can be ambiguous, for example, the following defines a single env-variable (`ONE`) with value `"TWO= THREE=world"`: ENV ONE TWO= THREE=world While we cannot deprecate/remove that syntax (as it would break existing Dockerfiles), we should reduce exposure of the format in our examples. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 0a0037c6fd259f34bef4ed29089d11dd9df7fe4c) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 10973d6ddf5697e3a5deab7e1a176f8b87d39aab Component: cli
1 parent fcc83c0 commit fb91a7f

8 files changed

Lines changed: 47 additions & 44 deletions

File tree

components/cli/docs/reference/builder.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,10 @@ Example (parsed representation is displayed after the `#`):
500500

501501
```dockerfile
502502
FROM 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

509509
Environment 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>
998997
ENV <key>=<value> ...
999998
```
1000999
10011000
The `ENV` instruction sets the environment variable `<key>` to the value
10021001
`<value>`. This value will be in the environment for all subsequent instructions
10031002
in 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,
10151005
quotes 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-
10341024
The environment variables set using `ENV` will persist when a container is run
10351025
from the resulting image. You can view the values using `docker inspect`, and
10361026
change 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
17681771
For example:
17691772

17701773
```dockerfile
1771-
ENV DIRPATH /path
1774+
ENV DIRPATH=/path
17721775
WORKDIR $DIRPATH/$DIRNAME
17731776
RUN pwd
17741777
```
@@ -1873,7 +1876,7 @@ this Dockerfile with an `ENV` and `ARG` instruction.
18731876
```dockerfile
18741877
FROM ubuntu
18751878
ARG CONT_IMG_VER
1876-
ENV CONT_IMG_VER v1.0.0
1879+
ENV CONT_IMG_VER=v1.0.0
18771880
RUN echo $CONT_IMG_VER
18781881
```
18791882

@@ -1894,7 +1897,7 @@ useful interactions between `ARG` and `ENV` instructions:
18941897
```dockerfile
18951898
FROM ubuntu
18961899
ARG 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}
18981901
RUN echo $CONT_IMG_VER
18991902
```
19001903

@@ -2030,7 +2033,7 @@ Consider another example under the same command line:
20302033
```dockerfile
20312034
FROM ubuntu
20322035
ARG CONT_IMG_VER
2033-
ENV CONT_IMG_VER $CONT_IMG_VER
2036+
ENV CONT_IMG_VER=$CONT_IMG_VER
20342037
RUN echo $CONT_IMG_VER
20352038
```
20362039

@@ -2045,7 +2048,7 @@ this Dockerfile:
20452048
```dockerfile
20462049
FROM ubuntu
20472050
ARG CONT_IMG_VER
2048-
ENV CONT_IMG_VER hello
2051+
ENV CONT_IMG_VER=hello
20492052
RUN echo $CONT_IMG_VER
20502053
```
20512054

components/cli/docs/reference/commandline/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ FROM busybox
742742
RUN echo hello > /hello
743743
RUN echo world >> /hello
744744
RUN touch remove_me /remove_me
745-
ENV HELLO world
745+
ENV HELLO=world
746746
RUN rm /remove_me
747747
```
748748

components/cli/docs/reference/commandline/commit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
7373

7474
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
7575

76-
$ docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3
76+
$ docker commit --change "ENV DEBUG=true" c3f279d17e0a svendowideit/testimage:version3
7777

7878
f5283438590d
7979

components/cli/docs/reference/commandline/import.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $ sudo tar -c . | docker import - exampleimagedir
7272
### Import from a local directory with new configurations
7373

7474
```bash
75-
$ sudo tar -c . | docker import --change "ENV DEBUG true" - exampleimagedir
75+
$ sudo tar -c . | docker import --change "ENV DEBUG=true" - exampleimagedir
7676
```
7777

7878
Note the `sudo` in this example – you must preserve

components/cli/e2e/image/build_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func TestBuildIidFileSquash(t *testing.T) {
116116
buildDir := fs.NewDir(t, "test-iidfile-squash-build",
117117
fs.WithFile("Dockerfile", fmt.Sprintf(`
118118
FROM %s
119-
ENV FOO FOO
120-
ENV BAR BAR
119+
ENV FOO=FOO
120+
ENV BAR=BAR
121121
RUN touch /fiip
122122
RUN touch /foop`, fixtures.AlpineImage)),
123123
)

components/cli/man/Dockerfile.5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ A Dockerfile is similar to a Makefile.
201201
from the resulting image. Use `docker inspect` to inspect these values, and
202202
change them using `docker run --env <key>=<value>`.
203203

204-
Note that setting "`ENV DEBIAN_FRONTEND noninteractive`" may cause
204+
Note that setting "`ENV DEBIAN_FRONTEND=noninteractive`" may cause
205205
unintended consequences, because it will persist when the container is run
206206
interactively, as with the following command: `docker run -t -i image bash`
207207

@@ -388,7 +388,7 @@ A Dockerfile is similar to a Makefile.
388388
```
389389
1 FROM ubuntu
390390
2 ARG CONT_IMG_VER
391-
3 ENV CONT_IMG_VER v1.0.0
391+
3 ENV CONT_IMG_VER=v1.0.0
392392
4 RUN echo $CONT_IMG_VER
393393
```
394394
Then, assume this image is built with this command:
@@ -408,7 +408,7 @@ A Dockerfile is similar to a Makefile.
408408
```
409409
1 FROM ubuntu
410410
2 ARG CONT_IMG_VER
411-
3 ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0}
411+
3 ENV CONT_IMG_VER=${CONT_IMG_VER:-v1.0.0}
412412
4 RUN echo $CONT_IMG_VER
413413
```
414414

components/cli/man/src/container/commit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ variable set to "true", you can create a new image based on that
2727
container by first getting the container's ID with `docker ps` and
2828
then running:
2929

30-
$ docker container commit -c="ENV DEBUG true" 98bd7fc99854 debug-image
30+
$ docker container commit -c="ENV DEBUG=true" 98bd7fc99854 debug-image

components/cli/man/src/image/import.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Import to docker via pipe and stdin:
3636
## Apply specified Dockerfile instructions while importing the image
3737
This example sets the docker image ENV variable DEBUG to true by default.
3838

39-
# tar -c . | docker image import -c="ENV DEBUG true" - exampleimagedir
39+
# tar -c . | docker image import -c="ENV DEBUG=true" - exampleimagedir
4040

4141
## When the daemon supports multiple operating systems
4242
If the daemon supports multiple operating systems, and the image being imported

0 commit comments

Comments
 (0)