Deploying Chirpstack without docker-compose (postgres connection refused)

Hello Chirpstack community,

I believe my problem is probably easy to solve, but I simply do not yet have enough experience with Docker to solve it.

Due to the way our DevOps teams configured our private cloud, its not possible to use docker-compose, i.e. they provided me with a running docker machine where I can deploy my containers.

Now I am trying to manually run all the individual docker containers, as specified in the default configuration:

My main problem is that I am not able to connect to the postgres database from Chirpstack (or any other postgres client for that matter)

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: Address not available
Is the server running on host ā€œlocalhostā€ (::1) and accepting
TCP/IP connections on port 5432?

I am running the postgres container as follows:

docker run -v ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d -v postgresqldata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=root postgres:14-alpine

and then Chirpstack as follows:

docker run -v ./configuration/chirpstack:/etc/chirpstack -v ./lorawan-devices:/opt/lorawan-devices -p 8080:8080 -e MQTT_BROKER_HOST=mosquitto -e REDIS_HOST=redis -e POSTGRESQL_HOST=localhost chirpstack/chirpstack:4 -c /etc/chirpstack

I suspect my problem is that the standalone containers are somehow not able to communicate with each other?

Could someone please provide some advice?

Hey :wave:,
Iā€™m not a docker specialist, but did you follow the error message and check on which port your PostgreSQL instance is running?

Please note that Docker Compose also handles the inter-networking between services specified within the docker-compose.yml file. If you are going to deploy individual containers, then these will all be isolated from each other, which is very likely the issue you are experiencing. E.g.

docker run -v ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d -v postgresqldata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=root postgres:14-alpine

does not expose any of the ports to the Docker host.

If you are not using Compose, then you would need to setup this networking between containers yourself.

Thanks for the quick replies guys!

As I suspected, the inter-container network communication was indeed the problem.

As @brocaar pointed out, it is necessary to setup the networking manually, but what is particularly important is to properly name the containers and use these names when running the Chirpstack container, i.e. for the Moquitto, Redis and Postgres container host names.

Here is what worked for me:

docker network create chirpnet

docker run --network chirpnet -d --name chirpstack_mosquitto -v ./configuration/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf -p 1883:1883 eclipse-mosquitto:2

docker run --network chirpnet -d --name chirpstack_redis -v redisdata:/data redis:7-alpine

docker run --network chirpnet -d --name chirpstack_postgres -v ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d -v postgresqldata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=root postgres:14-alpine

docker run --network chirpnet -d --name chirpstack_gateway -v ./configuration/chirpstack-gateway-bridge:/etc/chirpstack-gateway-bridge -p 1700:1700/udp chirpstack/chirpstack-gateway-bridge:4

docker run --network chirpnet -d --name chirpstack_rest_api -p 8090:8090 chirpstack/chirpstack-rest-api:4  --server chirpstack:8080 --bind 0.0.0.0:8090 --insecure

docker run --network chirpnet -d --name chirpstack_lns -v ./configuration/chirpstack:/etc/chirpstack -v ./lorawan-devices:/opt/lorawan-devices -p 8080:8080 -e MQTT_BROKER_HOST=chirpstack_mosquitto -e REDIS_HOST=chirpstack_redis -e POSTGRESQL_HOST=chirpstack_postgres chirpstack/chirpstack:4  -c /etc/chirpstack

I hope this helps someone in the future!

EDIT: it is also necessary to update the configuration files if you used other names for the containers using --name. In my particular case, it was necessary to update the Mosquitto server name in chirpstack-gateway-bridge.toml:

servers=["tcp://mosquitto:1883"] -> servers=["tcp://chirpstack_mosquitto:1883"]

2 Likes