From 429e2310c1184f7fff52bf9705a0b10167757f01 Mon Sep 17 00:00:00 2001 From: f-amine Date: Thu, 18 Jun 2026 14:09:45 +0100 Subject: [PATCH] fix(docker): bake server path into entrypoint, ignore runtime APP_NAME All three services crash-looped with Cannot find module '/app/apps/vibestack-vibestack-azmdyg/server.js' Dokploy injects its own APP_NAME (the project name) into every container, and env_file overrides image ENV, so the prior CMD `sh -c 'exec node apps/$APP_NAME/server.js'` resolved $APP_NAME to the project name -> wrong path, identical failure across all apps. Fix: write the resolved path into /app/start.sh at BUILD time from the build ARG, and CMD it. Runtime env can no longer influence the path. Verified: image built with APP_NAME=web boots cleanly even when run with -e APP_NAME=vibestack-vibestack-azmdyg injected (Next ready, health serves). Co-Authored-By: Claude Opus 4.8 (1M context) --- docker/Dockerfile.next | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.next b/docker/Dockerfile.next index 4f80abc..d24af29 100644 --- a/docker/Dockerfile.next +++ b/docker/Dockerfile.next @@ -69,8 +69,6 @@ ARG APP_PORT ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=${APP_PORT} -# Persist APP_NAME so the runtime CMD can resolve the standalone server path. -ENV APP_NAME=${APP_NAME} WORKDIR /app RUN addgroup -S nodejs && adduser -S nextjs -G nodejs @@ -79,9 +77,15 @@ COPY --from=builder --chown=nextjs:nodejs /repo/apps/${APP_NAME}/.next/standalon COPY --from=builder --chown=nextjs:nodejs /repo/apps/${APP_NAME}/.next/static ./apps/${APP_NAME}/.next/static COPY --from=builder --chown=nextjs:nodejs /repo/apps/${APP_NAME}/public ./apps/${APP_NAME}/public +# Bake the standalone entrypoint path into a script at BUILD time. We must not +# read APP_NAME from the runtime env: the platform injects its own env (Dokploy +# sets APP_NAME to the project name) and env_file overrides image ENV, which +# would point node at a nonexistent path. The value is fixed here per image. +RUN printf '#!/bin/sh\nexec node /app/apps/%s/server.js\n' "$APP_NAME" > /app/start.sh \ + && chmod +x /app/start.sh \ + && chown nextjs:nodejs /app/start.sh + USER nextjs EXPOSE ${APP_PORT} ENV HOSTNAME=0.0.0.0 -# Shell form so $APP_NAME expands at runtime; `exec` hands PID 1 to node so it -# receives SIGTERM for graceful shutdown. Exec-form JSON would not expand vars. -CMD ["sh", "-c", "exec node apps/$APP_NAME/server.js"] +CMD ["/app/start.sh"]