Postgres connecting issue in Docker image deployment

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:
1 Like

Hi there,

We don’t support docker-compose.yml deployments at the moment, typically we see customers setting a DATABASE_URL environment variable pointing at their DB host that the image uses,

Regards,

John B
Render Support, UTC+1 :uk:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.