I'm trying to create a docker-compose to run back-end and front-end, and database (PostgreSQL) at the same time but when I run it I get this error :
/usr/src/app/node_modules/@prisma/client/runtime/index.js:44801
api_1 | reject(new PrismaClientInitializationError(error2.message, this.config.clientVersion, error2.error_code));
api_1 | ^
api_1 |
api_1 | PrismaClientInitializationError: Can't reach database server at `postgres`:`5432`
api_1 |
api_1 | Please make sure your database server is running at `postgres`:`5432`.
api_1 | at /usr/src/app/node_modules/@prisma/client/runtime/index.js:44801:20 {
api_1 | clientVersion: '3.15.2',
api_1 | errorCode: 'P1001'
api_1 | }
the problem is connecting the application container with database container but how can I fix it?
my docker-compose:
version: '3.8'
services:
api:
build: back-end/
depends_on:
- postgres
environment:
DATABASE_URL: postgres://user:password@postgres:5432/db
NODE_ENV: development
PORT: 3000
ports:
- "8080:3000"
postgres:
image: postgres:10.4
ports:
- "5432:5432"
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: db
.env inside the back-end folder (this is for connecting nestjs/Prisma with the database):
DATABASE_URL="postgres://user:password@postgres:5432/db?schema=public"