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"]