SegFault
SegFault

Reputation: 2220

NodeJS: Can't connect to postgreSQL container from another container

I have container with a NodeJS application and it has to be linked to another container with a Postgres db. My docker-compose.yml is:

version: "3"
services:
  postgres:
    image: "postgres:9.5.6-alpine"
    container_name: postgres
    volumes:
      - /shared_folder/postgresql:/var/lib/postgresql
    ports:
      - "5432:5432"  
  web:
    build: .  
    container_name: web
    ports:
      - "3000:3000"
    links:
      - postgres 
    depends_on:
      - postgres 
    command: sh /usr/home/freebsd/wait-for-command.sh -c 'nc -z postgres 5432' 
    command: sh start.sh

On postgres container there is a db named "bucket", owned by user "user" with password "password".

When I type docker-compose up, and try to link the containers, after this message from console:

[INFO] console - postgres://user:password@localhost:5432/bucket

I get this error:

Error: Connection terminated
at [object Object].<anonymous> 

in /node_modules/massive/node_modules/deasync/index.js:46

where is the problem?

Upvotes: 0

Views: 574

Answers (1)

Rawkode
Rawkode

Reputation: 22592

You define command twice, which means your wait-for-command.sh is being overridden by sh start.sh and it's probably being run before PostgreSQL is ready to accept connections.

Upvotes: 1

Related Questions