Hello,
I was trying to deploy the node.js backend with postgres database using the Docker image, but the postgres does not connect and gives error. The docker image works perfectly locally in my machine.
I’m using docker-compose.yml in which my Postgres host (PGHOST) is set to ‘postgres-db’. which is the name of the database service. Do you have any ideas what can be the issue? And I wanted to know if docker-compose.yml is supported yet on Render.
Error:
/app/node_modules/pg-pool/index.js:45
Aug 29 08:26:06 AM Error.captureStackTrace(err);
Aug 29 08:26:06 AM ^
Aug 29 08:26:06 AM
Aug 29 08:26:06 AM Error: getaddrinfo ENOTFOUND postgres-db
Aug 29 08:26:06 AM at /app/node_modules/pg-pool/index.js:45:11
Aug 29 08:26:06 AM at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Aug 29 08:26:06 AM at async createTables (/app/database/db.js:20:20) {
Aug 29 08:26:06 AM errno: -3008,
Aug 29 08:26:06 AM code: 'ENOTFOUND',
Aug 29 08:26:06 AM syscall: 'getaddrinfo',
Aug 29 08:26:06 AM hostname: 'postgres-db'
Aug 29 08:26:06 AM }
Aug 29 08:26:06 AM
Aug 29 08:26:06 AM Node.js v18.17.1
My docker-compose.yml file:
services:
postgres-db:
image: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=${PGPASSWORD}
ports:
- "5432:5432"
app:
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres-db
ports:
- "3000:3000"
environment:
- PORT=3000
- PGHOST=${PGHOST}
- PGUSER=postgres
- PGDATABASE=postgres
- PGPASSWORD=${PGPASSWORD}
- PGPORT=5432
- ACCESS_TOKEN=${ACCESS_TOKEN}
volumes:
postgres-data: