Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docker/Dockerfile.next
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
Loading