0

I have telegram bot running from docker container and i'm trying to make connection to postgres from this container. Docker container and postgres are run on the same server.

Container crashes with an error:

psycopg2.OperationalError: connection to server at "127.0.0.1", port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?

Here is the pg_hba.conf:

TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
local   income_bot      income_bot                              password
local   happy_bot       happy_bot                               password
IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             127.0.0.1/32            trust
IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
Allow replication connections from localhost, by a user with the
replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

Seems like the problem in pg_hba.conf , but i don't know to configure it right

Code line with connection: connection = psycopg2.connect(database='happy_bot', user='happy_bot', password='test_password', host='111.111.11.11', port=5432) 111.111.11.11 - just for example I've been trying to use: host='localhost' , host='127.0.0.1' , also i've been trying to use my server ip.

Here is the docker run:

docker run -d --name h_bot1 -e API_TOKEN='Token example' --net=host happy_bot

TimurG
  • 1
  • 2

0 Answers0