1

I have a CentOS 7 server, on which individually postgres (port 5432) and docker is running.

Currently I am trying to access postgres database from my docker container. But I am getting the below error:

    at Connection.parseE (/usr/app/node_modules/pg/lib/connection.js:604:11)
    at Connection.parseMessage (/usr/app/node_modules/pg/lib/connection.js:401:19)
    at Socket.<anonymous> (/usr/app/node_modules/pg/lib/connection.js:121:22)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'error',
  length: 161,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '489',
  routine: 'ClientAuthentication' }```

I have change pg_hba.conf of my host postgres application that too didn't solve the issue.
Any help will be appreciated.
7
  • 1
    Please share more information: which port / IP does your postgres server bind to? is postgres also running in a container? Can you share a simple client scenario? e.g. a Dockerfile to build a client that fails to connect to postrges and the commands that you used to start the docker container Commented Oct 21, 2019 at 7:40
  • Thanks for the revert. 1)My postgres runs on port 5432 of host server. 2)Docker is also configured on same host. 3)There is no postgres running on any of the docker container. 4) Docker build is successful. 5) Command to run the image: docker run -d -p 3001:3001 <image name> Commented Oct 21, 2019 at 8:16
  • Thank you for the clarification. Are you trying to access the postgres server with the IP of the hostmachine? is the Postgres server bound to the IP of the hostmachine? (e.g. not 127.0.0.1 / localhost) Commented Oct 21, 2019 at 8:22
  • Yes I am using the IP of the hostmachine to connect. Commented Oct 21, 2019 at 8:24
  • Do you have firewall running on your CentOS 7 machine? e.g. firewalld? If so is the postgres port opened in your firewall configuration? Commented Oct 21, 2019 at 8:32

1 Answer 1

2

Thanks Clemans for your help, I got the solution. Issue was due to docker network since it was not able to connect to host. Since by default my container was running in docker network bridge. I changed that to run into host which solve my issue. Below is the command which I used to run my container docker run --network=host -d <image name>

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

1 Comment

Great! Thank you for posting the solution to your question :)

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.