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?