Skip to content

selfhost: own .next by node so runtime caches are writable - #45

Merged
codewarnab merged 1 commit into
codewarnab:mainfrom
xenon134:fix/selfhost-next-runtime-permissions
Nov 22, 2026
Merged

codewarnab merged 1 commit into
codewarnab:mainfrom
xenon134:fix/selfhost-next-runtime-permissions

Conversation

@xenon134

Copy link
Copy Markdown
Contributor

Problem

Running the self-host image as documented produces this on every prerender-cache update:

Failed to update prerender cache for /app Error: EACCES: permission denied, mkdir '/app/.next/server/route-cache'

The message repeats on each request. The prerender cache is never written.

Cause

deploy/selfhost/Dockerfile copies the build output without changing ownership:

COPY --from=build /app/.next ./.next

so the tree arrives as root:root, while the runtime stage ends with USER node. The
existing chown only covers the writable volumes:

RUN mkdir -p /gh .data && chown node:node /gh .data

Next writes server/route-cache and the image-optimizer caches under cache/ at request
time, so node cannot create them.

Fix

COPY --chown=node:node --from=build /app/.next ./.next

--chown on the copy avoids adding a recursive chown -R step, which would rewrite the
entire tree into another image layer.

Verification

  • ls -ld /app/.next in the published image reports root root, while the process runs as node.
  • Container logs show the EACCES on mkdir '/app/.next/server/route-cache'.
  • With a writable mount over that path the errors stop, confirming ownership as the only cause.

This does not change behaviour of the hosted deployment; it only affects the self-host image.

The runtime stage copied /app/.next as root, but the container runs as
node. Next writes .next/server/route-cache and the image caches under
.next/cache at request time, so every prerender-cache update failed with
EACCES and the cache was never written.

Use COPY --chown=node:node rather than a recursive chown, which would
rewrite the whole tree into another layer.
@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@xenon134 is attempting to deploy a commit to the Paws Team on Vercel.

A member of the Team first needs to authorize it.

@codewarnab

Copy link
Copy Markdown
Owner

Thanks for finding this and for the clear write-up. Using --chown on the COPY is the right fix, since it avoids an extra layer from chown -R. Merging now.

@codewarnab
codewarnab merged commit dd9db0a into codewarnab:main Nov 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants