fix(docker): make prod images actually build and boot#98
Merged
Conversation
Three bugs in docker/Dockerfile.next, none caught by CI (CI builds via
pnpm, never through the Dockerfile):
1. NEXT_PUBLIC_* are inlined at build time, but env_file only reaches
runtime, so `next build` died on missing NEXT_PUBLIC_APP_URL. Pass
the public vars as build args (compose interpolates them from the
deploy env via a shared YAML anchor) and set them as ENV in the
builder. Server vars get shape-valid placeholders at build only
(real secrets arrive at runtime via env_file; the runner is a
separate stage, so no secret enters any image layer).
2. `COPY ... public ... 2>/dev/null || true` is not shell — Docker
COPY parsed the redirect as a literal source and failed once the
build got far enough to reach it. web/admin ship no public/ dir, so
mkdir -p it in the builder and make the COPY unconditional.
3. CMD was exec-form JSON with ${APP_NAME}, which Docker does not
expand → "Cannot find module apps/${APP_NAME}/server.js". Persist
APP_NAME as ENV and use `sh -c 'exec node ...'` so it expands and
node still receives SIGTERM.
Verified locally: web + marketing images build; web container boots
(Next ready, /api/health serves) with only runtime env.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Dokploy deploy failed at
pnpm --filter ./apps/web run build(exit 1). Reproduced the exact docker build locally and found three bugs indocker/Dockerfile.next— none caught by CI, because CI builds withpnpm build(env present) and never exercises the Dockerfile.Bugs + fixes
NEXT_PUBLIC_*undefined at build →@vibestack/env/webthrows,next builddies. These are inlined into the client bundle at build time, butenv_fileonly reaches runtime. → Pass public vars as build args (compose interpolates them via a sharedx-public-build-argsanchor); builder sets them as ENV. Server vars get shape-valid placeholders at build so validation + module-load (new URL(APP_URL)in auth) pass; real secrets only arrive at runtime viaenv_file, and the runner is a separate stage so nothing leaks into image layers.COPY ... public ... 2>/dev/null || true—COPYisn't shell; Docker treated the redirect as a literal source and failed once the build reached it. web/admin have nopublic/. →mkdir -p publicin the builder, unconditional COPY.CMD ["node","apps/${APP_NAME}/server.js"]— exec-form JSON doesn't expand vars →Cannot find module apps/${APP_NAME}/server.js. → persistAPP_NAMEas ENV,CMD ["sh","-c","exec node apps/$APP_NAME/server.js"](expands + keeps SIGTERM).Verified locally (not just CI)
docker buildweb (no public dir) and marketing (has public dir): both succeed end to end.docker runweb with only runtime env: container boots,▲ Next.js Ready,/api/healthserves (503 only because no DB attached; authup, optional servicesdisabled).Deploy note
NEXT_PUBLIC_*must be present in the Dokploy Environment tab before building (they're build args now) — they already are in the documented env block.🤖 Generated with Claude Code