From 25c257d3367cb679e463cdfad56f178eb021dc18 Mon Sep 17 00:00:00 2001 From: Joe Garcia Date: Tue, 10 Dec 2024 09:29:36 -0800 Subject: [PATCH] fix(docker) nextjs unable to connect to db (#6119) * fix(docker): nextjs unable to connect to db * fix(docker): nextjs unable to connect to db * fix(docker): nextjs unable to connect to db --------- Co-authored-by: Marin Joe Garcia --- apps/nextjs-app/.env | 2 ++ docker/docker-compose.db.yml | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/apps/nextjs-app/.env b/apps/nextjs-app/.env index 06e482238d5..c7aed3a0ebb 100644 --- a/apps/nextjs-app/.env +++ b/apps/nextjs-app/.env @@ -17,6 +17,8 @@ NEXT_BUILD_ENV_SOURCEMAPS=false # When deploying on serverless/lambdas "?connection_limit=" should be 1 # @see https://www.prisma.io/docs/concepts/components/prisma-client/deployment#recommended-connection-limit PRISMA_DATABASE_URL=postgresql://nextjs:!ChangeMe!@localhost:5432/maindb?schema=public +# for docker use the container name for the host +#PRISMA_DATABASE_URL=postgresql://nextjs:!ChangeMe!@main-db:5432/maindb?schema=public # See https://github.com/soluble-io/cache-interop APP_CACHE_DSN= diff --git a/docker/docker-compose.db.yml b/docker/docker-compose.db.yml index b84e69a6fd7..9dfd8fd9101 100644 --- a/docker/docker-compose.db.yml +++ b/docker/docker-compose.db.yml @@ -12,6 +12,8 @@ services: - POSTGRES_DB=maindb - POSTGRES_PASSWORD=!ChangeMe! - POSTGRES_USER=nextjs + networks: + - nextjs-monorepo-example-network volumes: - db_data:/var/lib/postgresql/data:rw # you may use a bind-mounted host directory instead, @@ -20,3 +22,7 @@ services: volumes: db_data: + +networks: + nextjs-monorepo-example-network: + driver: bridge