-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
docker build multiple "--cache-from" docs clarification needed #8531
Comments
And what if we don't pass |
I think it won't work if you have multistage builds, with final image stripped down. We build images for intermediate stages using |
Has anyone figure out how this works? I've seen some posts about using comma separated values for the For example:
I've tried it out and it seems to work on one build runner (GitLab), but on another build runner (separate machine), it doesn't use the cache as I'd expect. Note that do run a It would be great to have more documentation about the |
@deepankar-j we've done it like this # build image with development dependencies
docker build \
--target builder \
--cache-from $BUILDER_IMAGE \
--cache-from $BUILDER_IMAGE_BASE \
-t $BUILDER_IMAGE \
.
# push for reuse in other builds
docker push $BUILDER_IMAGE
# build downsized production image
docker build \
--cache-from $BUILDER_IMAGE \
--cache-from $BUILDER_IMAGE_BASE \
--cache-from $PROD_IMAGE \
--cache-from $PROD_IMAGE_BASE \
-t $PROD_IMAGE \
.
docker push $PROD_IMAGE
Seems to work. |
Thanks @jacob87o2! After I posted my comment, I found the following comment on an issue, which indicates that a comma-separate value can be supplied to As per that comment, the order in which the arguments are provided seems to be important for cache matching. Nonetheless, thank you for responding. Hopefully, this will help others in the future. |
I think it's important to know the order that these caches are checked in, or to have some way to control the order. I currently have tags like |
There hasn't been any activity on this issue for a long time. Prevent issues from auto-closing with a /lifecycle stale |
@williamareynolds When I specify multiple cache-froms, they are processed in order. The comma separated refs I can't find documented anywhere. This is also mentioned here, but sadly missing in the docs: /remove-lifecycle stale |
Closed issues are locked after 30 days of inactivity. If you have found a problem that seems similar to this, please open a new issue. /lifecycle locked |
Problem description
I think we need some clarification on
--cache-from
argument in docker image build docs.How to pass multiple images?
docker build --cache-from first-image --cache-from second-image
or
docker build --cache-from first-image second-image
How does providing multiple cache-from images work? Does it take first image that is found (argument order matters)? Or does it pick the one with most cached layers?
I'm trying to use it in CI, with multi-stage build. Is this the right way to do it?
Let's assume I have a
Dockerfile
with build step (FROM ... as builder
) and setup step (FROM ...-alpine
).Also, let's assume we use git-flow and we want to use
develop
as base cache image, not last built tag (latest
).first step:
second step:
So, building image on feature branch, last branch build image should be used as cache and (if it's a new branch) it should fallback to
develop
right?Or am I mistaken? 🤔
Problem location
https://docs.docker.com/engine/reference/commandline/build/
Suggestions for a fix
I think these issues should be clarified in docs (
docker build
cli usage).Any response here also would be greatly appreciated!
The text was updated successfully, but these errors were encountered: