Next.js Discord

Discord Forum

How the hell am i supposed to run Nextjs + Prisma in Docker??

Unanswered
Clumber Spaniel posted this in #help-forum
Open in Discord
Clumber SpanielOP
like it always fails at build because it cant find my running database

9 Replies

I ran into a similar thing when hosting my backend in the same network as my next js app
Here's the workaround I made: https://github.com/vercel/next.js/issues/76913#issuecomment-3444041277
pretty much wherever i the sevrer you're communicating with docker use
export const dynamic = "force-dynamic"
the actual postgresql service takes a bit longer to become active compared to the container
you need to add a docker healthcheck
 db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 1s
      timeout: 5s
      retries: 10


taken from https://www.docker.com/blog/how-to-use-the-postgres-docker-official-image/
If using @Yi Lon Ma solution you need to use an older version of docker compose since v3 doesn't support healthchecks
oh
mb
Clumber SpanielOP
:peepo_think: thanks guys, ill try it later