Skip to content

Docker: nginx starts before Prisma, causing 502 on /api/ during db push and confusing health checks #1347

@nongvantinh

Description

@nongvantinh

📜 Description

Problem

In Dockerfile.dev, the CMD runs nginx && pnpm run pm2. Nginx listens on port 5000 immediately, while pm2-run still runs prisma db push first. Until Nest listens on 3000, location /api/ in nginx proxies to localhost:3000 and returns 502. That lasts for the whole Prisma phase.

For Kubernetes (or any orchestrator) this is awkward: HTTP probes to :5000/api/ see 502 even when the container is “healthy” for its real phase (migrating the DB).

Suggested direction

  1. Run prisma db push before nginx so nothing accepts on :5000 until after migration (or at least avoid nginx serving /api/ during Prisma).
  2. Split “migrate + start apps” so the container CMD can run: prismanginx → start PM2 apps without running Prisma twice.

I have a patch that adds a pm2-run-apps script (pnpm filters for backend/frontend/orchestrator only) and changes CMD to pnpm run prisma-db-push && nginx && pnpm run pm2-run-apps. Happy to open a PR if this matches your goals.

Environment

  • Image built from Dockerfile.dev (production-style container with nginx + PM2).

👟 Reproduction steps

Above

👍 Expected behavior

Dockerfile CMD: prisma-db-push → nginx → pm2-run-apps (was nginx first, which exposed :5000 during migration and caused 502 on /api/ until Nest was up).

👎 Actual Behavior with Screenshots

Image

💻 Operating system

Linux

🤖 Node Version

node:22.20-bookworm-slim

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions