Connecting docker container to a remote database

Hello,

can you help me please?
I have a Chirpstack 4 container.
I wish to use the Postgresql database I installed using “apt install…” locally on the machine in a container of a Chirpstack.
IP of my machine is 10.0.2.45 and Postgresql is running on ports 5432 and 5433.
I know I should be able to reach it because I made a container in the same docker network 172.19.0.0/16
and installed postgresql client to try to connect to a database on the same machine 10.0.2.45 and it did!
But then I try again multiple time with chirpstack and I keep getting this error:

2023-03-12T21:24:30.454103Z INFO chirpstack::storage: Setting up PostgreSQL connection pool
Error: Setup PostgreSQL connection pool error
Caused by:
timed out waiting for connection: could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5432?
2023-03-12T21:25:02.132215Z INFO chirpstack::cmd::root: Starting ChirpStack LoRaWAN Network Server version=“4.3.0” docs=“https://www.chirpstack.io/

and then it restarts again and again.

I see the problem is it tries to connect to localhost of the container and it doesn’t have postgresql server.
But I already gave environment variables:
- POSTGRESQL_HOST=10.0.2.45
- POSTGRESQL_PORT=5432

please help me.

Have you tried editing the chirpstack.toml configuration file directly?

I’m getting the same error but my circumstance is a little different. I’ve done the chirpstack v4 docker install on a debian 11 vagrant box. It appears there is something in the way the postgres db is configured that causes that problem. I have:

  • Mapped port 5432
  • Use localhost for the postgres host in the chirpstack .toml file
  • Added to postgresql.conf
    listen_addresses = ‘*’
  • Added to pg_hba.conf:
    host all all 0.0.0.0/0 md5
    host all all all trust

I’m looking for more things to try but have been unsucessful. Postgres worked fine with chirpstack v3 installed directly to debian 11 (not using docker)

Thank you for your help.

Regards,
Peter

To clarify - I’m using the postgres database set up by chirpstack docker. Originally I used localhost. I’ve also tried the ip of the vagrant box where docker is running.

docker-compose startup error:

chirpstack-docker-chirpstack-1                       | Error: Setup PostgreSQL connection pool error
chirpstack-docker-chirpstack-1                       |
chirpstack-docker-chirpstack-1                       | Caused by:
chirpstack-docker-chirpstack-1                       |     timed out waiting for connection: could not connect to server: Connection refused
chirpstack-docker-chirpstack-1                       |          Is the server running on host "localhost" (127.0.0.1) and accepting
chirpstack-docker-chirpstack-1                       |          TCP/IP connections on port 5432?
chirpstack-docker-chirpstack-1                       |     could not connect to server: Cannot assign requested address
chirpstack-docker-chirpstack-1                       |          Is the server running on host "localhost" (::1) and accepting
chirpstack-docker-chirpstack-1                       |          TCP/IP connections on port 5432?

From chirpstack.toml:
dsn="postgres://chirpstack:chirpstack@localhost/chirpstack?sslmode=disable"

This is running on a debian 11 vagrant box, I have also tried the eht0 and docker0 ip addresses as well as localhost for the hostname. I have tried all of this both with and without the postgres configuration changes mentioned above.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.