1

I have a node app that uses postgres and sequelize. I have a docker file that will run my server. I also have a docker compose file that will run a web image and db image that link my docker images and connect them together.

I am able to get my server running thorugh the docker file. I am trying to use the docker-compose file to run the database with it and and get them to work. I am getting a connection error with the database that is trying to connect and I am not sure where this error is coming from...

Dockerfile

FROM node:10
WORKDIR /app
COPY package.json ./app
RUN npm install
COPY . /app
CMD npm start
EXPOSE 5585

dock compose file:

version: "2"
services: 
  web:
    build: .
    ports: 
      - 80:5585
    command: npm start 
    depends_on:
      - db
    environment:
      - DATABASE_URL=postgres://username:password@db:5432/addidas
  db:
    image: postgres 
    restart: always
    ports:
      - "5432:5432"
    environment: 
      - POSTGRES_USER=username
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=addidas

I am also using sequelize to connect my database with express. Do i need to change anythign to do that.

ERROR:

web_1  | Fri, 09 Nov 2018 18:26:47 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:242:13
web_1  | server is running at http://localhost:3001
web_1  | { SequelizeConnectionRefusedError: connect ECONNREFUSED 172.19.0.3:5432
web_1  |     at connection.connect.err (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:116:24)
web_1  |     at Connection.connectingErrorHandler (/app/node_modules/pg/lib/client.js:140:14)
web_1  |     at Connection.emit (events.js:182:13)
web_1  |     at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:71:10)
web_1  |     at Socket.emit (events.js:182:13)
web_1  |     at emitErrorNT (internal/streams/destroy.js:82:8)
web_1  |     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
web_1  |     at process._tickCallback (internal/process/next_tick.js:63:19)
web_1  |   name: 'SequelizeConnectionRefusedError',
web_1  |   parent:
web_1  |    { Error: connect ECONNREFUSED 172.19.0.3:5432
web_1  |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
web_1  |      errno: 'ECONNREFUSED',
web_1  |      code: 'ECONNREFUSED',
web_1  |      syscall: 'connect',
web_1  |      address: '172.19.0.3',
web_1  |      port: 5432 },
web_1  |   original:
web_1  |    { Error: connect ECONNREFUSED 172.19.0.3:5432
web_1  |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
web_1  |      errno: 'ECONNREFUSED',
web_1  |      code: 'ECONNREFUSED',
web_1  |      syscall: 'connect',
web_1  |      address: '172.19.0.3',
web_1  |      port: 5432 } }
web_1  | { SequelizeConnectionRefusedError: connect ECONNREFUSED 172.19.0.3:5432
web_1  |     at connection.connect.err (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:116:24)
web_1  |     at Connection.connectingErrorHandler (/app/node_modules/pg/lib/client.js:140:14)
web_1  |     at Connection.emit (events.js:182:13)
web_1  |     at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:71:10)
web_1  |     at Socket.emit (events.js:182:13)
web_1  |     at emitErrorNT (internal/streams/destroy.js:82:8)
web_1  |     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
web_1  |     at process._tickCallback (internal/process/next_tick.js:63:19)
web_1  |   name: 'SequelizeConnectionRefusedError',
web_1  |   parent:
web_1  |    { Error: connect ECONNREFUSED 172.19.0.3:5432
web_1  |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
web_1  |      errno: 'ECONNREFUSED',
web_1  |      code: 'ECONNREFUSED',
web_1  |      syscall: 'connect',
web_1  |      address: '172.19.0.3',
web_1  |      port: 5432 },
web_1  |   original:
web_1  |    { Error: connect ECONNREFUSED 172.19.0.3:5432
web_1  |        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
web_1  |      errno: 'ECONNREFUSED',
web_1  |      code: 'ECONNREFUSED',
web_1  |      syscall: 'connect',
web_1  |      address: '172.19.0.3',
web_1  |      port: 5432 } }
1
  • Man can I hv your comment ? Commented Nov 12, 2018 at 10:53

2 Answers 2

1

1st change to 5432 to defalut postgres port

db:
image: postgres 
restart: always
ports:
  - "5432:3306" //default postgres port 
environment: 
  - POSTGRES_USER=username
  - POSTGRES_PASSWORD=password
  - POSTGRES_DB=addidas
  1. Allow the port you want to connect

sudo ufw allow 5432

Sign up to request clarification or add additional context in comments.

Comments

0

try:

...
web:
    build: 
      context: .
    ports: 
      - 80:5585
    command: npm start
    network_mode: service:db 
    links:
      - db
    environment:
      - DATABASE_URL=postgres://username:password@db:5432/addidas
...

Another thing is that from the expose line I guess that you want to run the node app on port 5585. But it is actually running on port 3001 (Based on the 2. line of the error message)

1 Comment

can you post the connection code from the nodejs app?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.