Skip to content

fix(docker): NuGet cache mount breaks parallel and pruned builds - #839

Merged
joszz merged 1 commit into
mainfrom
fix/docker-nuget-cache-race
Dec 1, 2026
Merged

joszz merged 1 commit into
mainfrom
fix/docker-nuget-cache-race

Conversation

@joszz

@joszz joszz commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Follow-up to #836. Building with docker-compose.build.yml (as on Unraid) failed in dotnet restore:

error : Could not find file '/root/.nuget/packages/serilog/4.4.0/zzhu1xit.trf'

Causes

  1. Parallel restores in one mount. Compose builds the API and Worker at the same time, and both use the nuget cache mount, which BuildKit shares between builds by default. NuGet guards package extraction with lock files in /tmp, but each build container has its own /tmp, so the two restores remove each other's temp files. sharing=locked makes concurrent builds take turns on the mount.
  2. A cached restore layer with an empty mount. BuildKit's layer cache does not look at the mount, so after BuildKit evicts the mount (garbage collection, docker builder prune) it can still reuse the restore layer. publish --no-restore then fails with NETSDK1064: Package ... was not found. publish now restores itself: a quick check when the packages are there, a download when they are not.

The same applies to the all-in-one Dockerfile. The images themselves do not change.

Checked

  • Before the fix: docker compose -f docker-compose.yml -f docker-compose.build.yml build --no-cache api worker, with a fresh mount id each round, failed in 4 of 4 rounds with the same error.
  • After the fix: the same command passed in 4 of 4 rounds.
  • Cached restore with an empty mount: this failed with NETSDK1064 before. Now publish restores and the build succeeds.
  • The all-in-one builds, and hadolint passes.

🤖 Generated with Claude Code

Two problems with the cache mount from #836:

- Compose builds the API and Worker at once, and both restored into the
  shared `nuget` mount. NuGet keeps its extraction locks in each
  container's own /tmp, so the two restores deleted each other's temp
  files: "Could not find file '/root/.nuget/packages/serilog/4.4.0/
  zzhu1xit.trf'". sharing=locked makes them take turns.
- BuildKit's layer cache ignores the mount, so the restore layer can be
  reused after the mount was evicted or pruned. `publish --no-restore`
  then failed with NETSDK1064. publish now restores itself, which is a
  quick check when the packages are already there.

Reproduced both with `docker compose -f docker-compose.yml -f
docker-compose.build.yml build --no-cache api worker` and a fresh mount
id: 4 of 4 rounds failed before, 4 of 4 pass after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joszz
joszz enabled auto-merge December 1, 2026 09:08
@joszz
joszz merged commit 9245063 into main Dec 1, 2026
28 checks passed
@joszz
joszz deleted the fix/docker-nuget-cache-race branch December 1, 2026 09:09
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.

1 participant