Random LABEL snp-multi-stage-id invalidates docker cache
See original GitHub issueIssue Description
Expected behaviour
I’m currently writing second post about docker cache efficiency on SBT. My main focus is to use docker cache in CI environments as much as possible. Already managed great improvements but there is problem with random generated Labels.
LABEL snp-multi-stage="intermediate"
LABEL snp-multi-stage-id="44857d33-aef2-4d80-b811-7d1ed9b1891d"
Executing second command always invalidates cache which is not always expected.
Especially when dockerAutoremoveMultiStageIntermediateImages := false
is used.
I suggest to use something deterministic like stage0-(packageName in Docker).value
Actual behaviour
Step 1/20 : FROM repo.mycompany.com/team/openjre:8u242 as stage0
[info] ---> a020ce624573
[info] Step 2/20 : LABEL snp-multi-stage="intermediate"
[info] ---> Using cache
[info] ---> 9abeed0b5a9f
[info] Step 3/20 : LABEL snp-multi-stage-id="44857d33-aef2-4d80-b811-7d1ed9b1891d"
[info] ---> Running in 072dfdce55ad
[info] Removing intermediate container 072dfdce55ad
[info] ---> 554d25368747
[info] Step 4/20 : WORKDIR /opt/my-app
[info] ---> Running in 49f3e275dc8c
As you can see cache works with the first label, but gets invalidated after second, random label. @mkurz What do you think about deterministic label?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
What causes a cache invalidation when building a Dockerfile?
Each command creates a new layer, that sits on top of the old one. Thus, layers are invalidated from the changed command, and...
Read more >Docker Cache Invalidation (#26910) · Issues - gitlab-runner
The tl;dr is that the remote docker cache appears to be invalidated in a situation which it should not be. This triggers a...
Read more >Optimizing builds with cache management
In other words, Docker will invalidate the cache for this layer. Image layer diagram, but now with the link between COPY and WORKDIR...
Read more >Surgically Busting the Docker Cache - zwischenzugs
bustcache :).*/\1 $RANDOM/" Dockerfile && docker build -t tag . The perl command will ensure that the line is changed to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the workaround! There’s just a negation missing, it should be:
case Cmd("LABEL", args @ _*) => !args.head.startsWith("snp-multi-stage")
In general I believe a deterministic id should be the default. More users are concerned with a fast build compared to ones inspecting their failed builds.
If you can live without those labels, it’s possible to simply remove then as a workaround