Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some docs about build-arg's impact on the cache #18161

Merged
merged 1 commit into from Nov 23, 2015

Conversation

duglin
Copy link
Contributor

@duglin duglin commented Nov 23, 2015

Closes #18017

Signed-off-by: Doug Davis dug@us.ibm.com

In this example, the cache miss will occur on line 3 because the value of
an environment variable (which is saved in the resulting image) is changed
as we change the `CONT_IMG_VER` build arg value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention that in this case, the value is persisted in the final image, because it is now used in an ENV? Possibly general knowledge, but may something that trip users.

Edit: ignore, was reading to fast, it is mentioned in the text 😊

@thaJeztah
Copy link
Member

Ignore my previous comment, lol.

Thanks @duglin, LGTM!

ping @SvenDowideit @moxiegirl PTAL

@@ -1135,6 +1135,38 @@ corresponding `ARG` instruction in the Dockerfile.
To use these, simply pass them on the command line using the `--build-arg
<varname>=<value>` flag.

### Impact on build caching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin thanks for the contribution. A few tweaks...

Impact on build caching

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
Dockerfile defines an ARG variable its value is different from a previous
build, then a "cache miss" occurs upon its first usage, not its declaration.
For example, consider this Dockerfile:

1 FROM ubuntu
2 ARG 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 3 does not cause a cache miss; Line 3 does cause a cache
miss. The definition on line 2 has no impact on the resulting image. The RUN
on line 3 executes a command and in doing so defines a set of environment
variables, including CONT_IMG_VER. At that point, the ARG variable may
impact the resulting image, so a cache miss occurs.

Consider another example under the same command line:

1 FROM ubuntu
2 ARG CONT_IMG_VER
3 ENV CONT_IMG_VER $CONT_IMG_VER
4 RUN echo $CONT_IMG_VER

In this example, the cache miss occurs on line 3. The miss happens because the variable's value the ENV references the ARG variable and that variable is changed through the command line. In this example, the ENV command causes the image to include value.

@duglin
Copy link
Contributor Author

duglin commented Nov 23, 2015

@moxiegirl ok picked up your edits - made a few minor tweaks due to missing words, but otherwise just copy-n-pasted. PTAL

In this example, the cache miss occurs on line 3. The miss happens because
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`
command causes the image to include value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is missing a word: "to include value", the value perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Closes moby#18017

Signed-off-by: Doug Davis <dug@us.ibm.com>
@thaJeztah
Copy link
Member

Thanks @duglin, LGTM

counting @moxiegirl's example as the second LGTM 😇

thaJeztah added a commit that referenced this pull request Nov 23, 2015
Add some docs about build-arg's impact on the cache
@thaJeztah thaJeztah merged commit 5017a5d into moby:master Nov 23, 2015
@moxiegirl
Copy link
Contributor

@duglin Thank you! My mom is visiting so I was trying to talk and write at the same time. Have a Happy Thanksgiving!

@duglin duglin deleted the Issue18017 branch February 19, 2016 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants