mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
make the cache miss clear
Signed-off-by: mikelinjie <294893458@qq.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 66b8714da4
)
This commit is contained in:
parent
cc5c9013d9
commit
e941f698da
1 changed files with 29 additions and 8 deletions
|
@ -1174,8 +1174,10 @@ To use these, simply pass them on the command line using the `--build-arg
|
||||||
`ARG` variables are not persisted into the built image as `ENV` variables are.
|
`ARG` variables are not persisted into the built image as `ENV` variables are.
|
||||||
However, `ARG` variables do impact the build cache in similar ways. If a
|
However, `ARG` variables do impact the build cache in similar ways. If a
|
||||||
Dockerfile defines an `ARG` variable whose value is different from a previous
|
Dockerfile defines an `ARG` variable whose value is different from a previous
|
||||||
build, then a "cache miss" occurs upon its first usage, not its declaration.
|
build, then a "cache miss" occurs upon first use of the `ARG` variable. The
|
||||||
For example, consider this Dockerfile:
|
declaration of the `ARG` variable does not count as a use.
|
||||||
|
|
||||||
|
For example, consider these two Dockerfile:
|
||||||
|
|
||||||
```
|
```
|
||||||
1 FROM ubuntu
|
1 FROM ubuntu
|
||||||
|
@ -1183,12 +1185,17 @@ For example, consider this Dockerfile:
|
||||||
3 RUN echo $CONT_IMG_VER
|
3 RUN echo $CONT_IMG_VER
|
||||||
```
|
```
|
||||||
|
|
||||||
If you specify `--build-arg CONT_IMG_VER=<value>` on the command line the
|
```
|
||||||
specification on line 2 does not cause a cache miss; line 3 does cause a cache
|
1 FROM ubuntu
|
||||||
miss. The definition on line 2 has no impact on the resulting image. The `RUN`
|
2 ARG CONT_IMG_VER
|
||||||
on line 3 executes a command and in doing so defines a set of environment
|
3 RUN echo hello
|
||||||
variables, including `CONT_IMG_VER`. At that point, the `ARG` variable may
|
```
|
||||||
impact the resulting image, so a cache miss occurs.
|
|
||||||
|
If you specify `--build-arg CONT_IMG_VER=<value>` on the command line, in both
|
||||||
|
cases, the specification on line 2 does not cause a cache miss; line 3 does
|
||||||
|
cause a cache miss.`ARG CONT_IMG_VER` causes the RUN line to be identified
|
||||||
|
as the same as running `CONT_IMG_VER=<value>` echo hello, so if the `<value>`
|
||||||
|
changes, we get a cache miss.
|
||||||
|
|
||||||
Consider another example under the same command line:
|
Consider another example under the same command line:
|
||||||
|
|
||||||
|
@ -1203,6 +1210,20 @@ the variable's value in the `ENV` references the `ARG` variable and that
|
||||||
variable is changed through the command line. In this example, the `ENV`
|
variable is changed through the command line. In this example, the `ENV`
|
||||||
command causes the image to include the value.
|
command causes the image to include the value.
|
||||||
|
|
||||||
|
If an `ENV` instruction overrides an `ARG` instruction of the same name, like
|
||||||
|
this Dockerfile:
|
||||||
|
|
||||||
|
```
|
||||||
|
1 FROM ubuntu
|
||||||
|
2 ARG CONT_IMG_VER
|
||||||
|
3 ENV CONT_IMG_VER hello
|
||||||
|
4 RUN echo $CONT_IMG_VER
|
||||||
|
```
|
||||||
|
|
||||||
|
Line 3 does not cause a cache miss because the value of `CONT_IMG_VER` is a
|
||||||
|
constant (`hello`). As a result, the environment variables and values used on
|
||||||
|
the `RUN` (line 4) doesn't change between builds.
|
||||||
|
|
||||||
## ONBUILD
|
## ONBUILD
|
||||||
|
|
||||||
ONBUILD [INSTRUCTION]
|
ONBUILD [INSTRUCTION]
|
||||||
|
|
Loading…
Add table
Reference in a new issue