Skip to content

Commit 491d28c

Browse files
authored
Merge pull request #23795 from dvdksn/workdir-cachebust
build: WORKDIR+SOURCE_DATE_EPOCH cache invalidation
2 parents e6879b9 + 4865382 commit 491d28c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

content/manuals/build/cache/invalidation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ If your build contains several layers and you want to ensure the build cache is
4444
reusable, order the instructions from less frequently changed to more
4545
frequently changed where possible.
4646

47+
## WORKDIR and SOURCE_DATE_EPOCH
48+
49+
The `WORKDIR` instruction respects the `SOURCE_DATE_EPOCH` build argument when
50+
determining cache validity. Changing `SOURCE_DATE_EPOCH` between builds
51+
invalidates the cache for `WORKDIR` and all subsequent instructions.
52+
53+
`SOURCE_DATE_EPOCH` sets timestamps for files created during the build. If you
54+
set this to a dynamic value like a Git commit timestamp, the cache breaks with
55+
each commit. This is expected behavior when tracking build provenance.
56+
57+
For reproducible builds without frequent cache invalidation, use a fixed
58+
timestamp:
59+
60+
```console
61+
$ docker build --build-arg SOURCE_DATE_EPOCH=0 .
62+
```
63+
4764
## RUN instructions
4865

4966
The cache for `RUN` instructions isn't invalidated automatically between builds.

0 commit comments

Comments
 (0)