Closes #18017
Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -562,7 +562,7 @@ ADD has two forms: |
| 562 | 562 |
whitespace) |
| 563 | 563 |
|
| 564 | 564 |
The `ADD` instruction copies new files, directories or remote file URLs from `<src>` |
| 565 |
-and adds them to the filesystem of the container at the path `<dest>`. |
|
| 565 |
+and adds them to the filesystem of the container at the path `<dest>`. |
|
| 566 | 566 |
|
| 567 | 567 |
Multiple `<src>` resource may be specified but if they are files or |
| 568 | 568 |
directories then they must be relative to the source directory that is |
| ... | ... |
@@ -1135,6 +1135,40 @@ corresponding `ARG` instruction in the Dockerfile. |
| 1135 | 1135 |
To use these, simply pass them on the command line using the `--build-arg |
| 1136 | 1136 |
<varname>=<value>` flag. |
| 1137 | 1137 |
|
| 1138 |
+### Impact on build caching |
|
| 1139 |
+ |
|
| 1140 |
+`ARG` variables are not persisted into the built image as `ENV` variables are. |
|
| 1141 |
+However, `ARG` variables do impact the build cache in similar ways. If a |
|
| 1142 |
+Dockerfile defines an `ARG` variable whose value is different from a previous |
|
| 1143 |
+build, then a "cache miss" occurs upon its first usage, not its declaration. |
|
| 1144 |
+For example, consider this Dockerfile: |
|
| 1145 |
+ |
|
| 1146 |
+``` |
|
| 1147 |
+1 FROM ubuntu |
|
| 1148 |
+2 ARG CONT_IMG_VER |
|
| 1149 |
+3 RUN echo $CONT_IMG_VER |
|
| 1150 |
+``` |
|
| 1151 |
+ |
|
| 1152 |
+If you specify `--build-arg CONT_IMG_VER=<value>` on the command line the |
|
| 1153 |
+specification on line 2 does not cause a cache miss; line 3 does cause a cache |
|
| 1154 |
+miss. The definition on line 2 has no impact on the resulting image. The `RUN` |
|
| 1155 |
+on line 3 executes a command and in doing so defines a set of environment |
|
| 1156 |
+variables, including `CONT_IMG_VER`. At that point, the `ARG` variable may |
|
| 1157 |
+impact the resulting image, so a cache miss occurs. |
|
| 1158 |
+ |
|
| 1159 |
+Consider another example under the same command line: |
|
| 1160 |
+ |
|
| 1161 |
+``` |
|
| 1162 |
+1 FROM ubuntu |
|
| 1163 |
+2 ARG CONT_IMG_VER |
|
| 1164 |
+3 ENV CONT_IMG_VER $CONT_IMG_VER |
|
| 1165 |
+4 RUN echo $CONT_IMG_VER |
|
| 1166 |
+``` |
|
| 1167 |
+In this example, the cache miss occurs on line 3. The miss happens because |
|
| 1168 |
+the variable's value in the `ENV` references the `ARG` variable and that |
|
| 1169 |
+variable is changed through the command line. In this example, the `ENV` |
|
| 1170 |
+command causes the image to include the value. |
|
| 1171 |
+ |
|
| 1138 | 1172 |
## ONBUILD |
| 1139 | 1173 |
|
| 1140 | 1174 |
ONBUILD [INSTRUCTION] |