nextjs - ✅(Solved) Fix Docker standalone deployment missing .next/cache causes cold cache on every deploy [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#90648Fetched 2026-04-08 00:19:43
View on GitHub
Comments
3
Participants
3
Timeline
15
Reactions
0
Assignees
Timeline (top)
commented ×3issue_type_changed ×2labeled ×2assigned ×1

Fix Action

Fixed

PR fix notes

PR #90651: example: restore .next handling for with-docker examples

Description (problem / solution / changelog)

  • Remove BuildKit cache mount on .next/cache that trapped fetch cache in a volume unreachable by the runner stage
  • Restore mkdir .next && chown in runner stage for writable prerender cache
  • Add commented-out COPY .next/cache line as opt-in for persisting build-time fetch cache
  • Apply same fixes to Dockerfile.bun (only needed the mkdir/chown, it never had the BuildKit mount)

Closes #90648

Changed files

  • examples/with-docker-export-output/README.md (modified, +14/-15)
  • examples/with-docker/Dockerfile (modified, +17/-2)
  • examples/with-docker/Dockerfile.bun (modified, +11/-0)
  • examples/with-docker/README.md (modified, +13/-9)

Code Example

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static


### Current vs. Expected behavior

Docker standalone deployment missing .next/cache causes cold cache on every deploy


### Provide environment information
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

Maintainer note: Use proper repository links, or proper issue types. In some cases, issues that game the system like this will be closed too.

To Reproduce

Link to the code that reproduces this issue

https://github.com/vercel/next.js/tree/canary/examples/with-docker

Current vs. Expected behavior

Current: The official Docker example (examples/with-docker/Dockerfile) only copies .next/standalone and .next/static to the production stage. The .next/cache directory (containing fetch-cache entries populated during build by generateStaticParams + "use cache" functions) is not included in the final image. Every deployment starts with an empty cache.

Expected: The .next/cache directory should be copied to the production stage so build-time cache persists across deployments.

What happened?

When using Next.js 16 with cacheComponents: true, "use cache", and generateStaticParams, the build populates .next/cache/fetch-cache/ with all cached results (~384 entries, ~11MB in our case).

The official Docker example's runner stage only copies:

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static


### Current vs. Expected behavior

Docker standalone deployment missing .next/cache causes cold cache on every deploy


### Provide environment information

```bash
node:25-alpine

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

extent analysis

Fix Summary

Add the .next/cache folder to the production stage of the Dockerfile (and make sure it isn’t excluded by .dockerignore). This preserves the fetch‑cache generated by generateStaticParams / "use cache" across deployments.


Step‑by‑Step Fix Plan

  1. Check .dockerignore
    Ensure the line /.next (or /.next/cache) is removed or overridden, otherwise the folder will be omitted from the build context.

  2. Update the Dockerfile (example based on the official with‑docker example):

    # ---------- Builder ----------
    FROM node:20-alpine AS builder
    WORKDIR /app
    COPY package*.json ./
    RUN npm ci
    COPY . .
    RUN npm run build   # creates .next/standalone, .next/static, .next/cache
    
    # ---------- Production ----------
    FROM node:20-alpine AS runner
    WORKDIR /app
    
    # copy runtime files
    COPY --from=builder /app/package*.json ./
    RUN npm ci --omit=dev && npm cache clean --force
    
    # copy the built app
    COPY --from=builder /app/.next/standalone ./
    COPY --from=builder /app/.next/static ./.next/static
    
    # <-- NEW: copy the cache folder -->
    COPY --from=builder /app/.next/cache ./.next/cache

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix Docker standalone deployment missing .next/cache causes cold cache on every deploy [1 pull requests, 3 comments, 3 participants]