How to remove mosquitto from Docker Compose?

Hi,

I have a server setup with a running mosquitto instance and I´m thinking of removing mosquitto from the ChirpStack Docker Compose file and using the active mosquitto instance. Is it possible and if yes, how can I do it?

My current setup looks as follows, but the ChirpStack and the Gateway bridge container can not connect to MQTT.

version: "3"

services:
  ChirpStack:
    image: chirpstack/chirpstack:4
    container_name: ChirpStack
    restart: unless-stopped
    command: -c /etc/chirpstack
    volumes:
      - ./configuration/CA:/opt/CA
      - ./configuration/chirpstack:/etc/chirpstack
      - ./lorawan-devices:/opt/lorawan-devices
    depends_on:
      - ChirpStack_Postgres
      - ChirpStack_Redis
    environment:
      - MQTT_BROKER_HOST=mosquitto
      - REDIS_HOST=ChirpStack_Redis
      - POSTGRESQL_HOST=ChirpStack_Postgres
    ports:
      - 8580:8080

  ChirpStack_Gateway_Bridge_EU868:
    image: chirpstack/chirpstack-gateway-bridge:4
    container_name: ChirpStack-Gateway-Bridge-EU868
    restart: unless-stopped
    ports:
      - 8570:1700/udp
    volumes:
      - ./configuration/chirpstack-gateway-bridge:/etc/chirpstack-gateway-bridge

  ChirpStack_REST_API:
    image: chirpstack/chirpstack-rest-api:4
    container_name: ChirpStack-REST-API
    restart: unless-stopped
    command: --server chirpstack:8080 --bind 0.0.0.0:8090 --insecure
    ports:
      - 8090:8090
    depends_on:
      - ChirpStack

  ChirpStack_Postgres:
    image: postgres:14-alpine
    container_name: ChirpStack-Postgres
    restart: unless-stopped
    volumes:
      - ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d
      - ChirpStack_PostgresData:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=root

  ChirpStack_Redis:
    image: redis:7-alpine
    container_name: ChirpStack-Redis
    restart: unless-stopped
    volumes:
      - ChirpStack_RedisData:/data

volumes:
  ChirpStack_PostgresData:
  ChirpStack_RedisData:

So what is wrong here?

Thank you for help!

Each service in the same stack (same docker-compose.yml file) share a common bridge network named after the folder where you have the docker-compose.yml file (you can check this network by typing docker network ls). All those services can resolve the other by the service name, so when mosquitto is in the same docker-compose.yml file the chirpstack service can see it under mosquitto.

But now you have mosquitto in a different stack and therefore it’s not on the same virtual network as chirpstack. The fastest way to make it work if mosquitto is exposing the 1883 port is changing the MQTT_BROKER_HOST environment variable to the host IP where mosquitto is running.

Hi,

thank you. That helped! But why does localhost not work? My guess is that localhost will refer to localhost of the container. Is this correct?

I did the same now for the gateway bridge by changing the IP address of the broker in chirpstack-gateway-bridge.toml too. But it didn´t work there when I tried the same approach as with ChirpStack by changing servers=["tcp://192.168.178.103:1883"] to servers=["tcp://$MQTT_BROKER_HOST:1883"] in
chirpstack-gateway-bridge.toml and adding the environment variable to the service. Do you know why?

The environment variables works for ChirpStack and doesnot work for Chirpstack gateway bridge for my case too.