Friday, 26 May 2017

nodejs not connects to postgresql on docker-compose containers

I am having problems connecting to my postgresql database using nodejs. I have all mounted with docker-compose.

version: "2"
services:
  server:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - ./:/usr/src/app
    links:
      - db
  db:
    image: postgres:9.6.2
    ports:
      - "5432:5432"
    volumes:
      - db_data:/var/lib/postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: 123
      POSTGRES_USER: test
      POSTGRES_DB: test_db

volumes:
  db_data:

I can connect to the database using PG Admin and DBeaver. I also can create tables or modify tables and any CRUD operation, but when I try it using nodejs it does not work. I am using db-migrate and db-migrate-pg.

{
  "dev": {
    "driver": "pg"
  },
  "pg": {
    "driver": "pg",
    "user": "test",
    "password": "123",
    "host": "postgres://localhost:5432",
    "database": "test_db",
    "schema": "public"
  }
}

When I try to run the migration I get this error:

Error: connect ECONNREFUSED 127.0.0.1:5432
    at Object.exports._errnoException (util.js:1018:11)
    at exports._exceptionWithHostPort (util.js:1041:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)



via abaracedo

No comments:

Post a Comment