External ports vs internal ports in docker-compose.yml?

My file structure is such that I have a docker-compose.yml which sets up a bunch of services (mosquitto, chirpstack, etc.) to run. They all have volumes: pointing to their configuration files…All seems to work. I wanted to understand better the idea of the internal docker port vs the external system ports so I have been trying some things and not quite found the key.

The question is, within docker-compose.yml :
Using the mosquitto service as the example :

    ports:
      - 1883:183

the other services that have a dependency on mosquitto will they reference the internal port 183 or the external system port 1883 within their own configuration files?

I have tried a variety of things and seem to break the system when not 1883:1883 and all config files use 1883. AI seems to say use the 183 but when I make that change within the chirpstack-gateway-bridge.toml file

servers=["tcp://mosquitto:183"]

the gateway goes offline on the chirpstack site.

Heres a breakdown of the internal / external port differences: What is the difference between ports and expose in docker-compose? - Stack Overflow

My assumption is that you are not changing the associated bind for the service. Just because you change the docker compose and gateway bridge to route data to a specific port of a service, does not mean the service is actually listening on that port. So in this example, did you create a listener on port 183 in your mosquitto.conf? For Chirpstack the equivalent is a line in your Chirpstack.toml that specifies the API bind, this is the port that it uses for the UI.

I can confirm that it’s possible in the docker setup to change the ports for any of the services to whatever you want as long as you properly change all the necessary configuration.

So my chirpstack.toml has :

 enabled=["mqtt"]

  [integration.mqtt]
    server="tcp://$MQTT_BROKER_HOST:183/"

my chirpstack-gateway-bridge.toml has

[integration.mqtt.auth.generic]
servers=["tcp://mosquitto:183"]

my mosquitto.conf file has

listener 183
allow_anonymous true

and my docker-compose.yml has

 mosquitto:
    container_name: broker
    image: eclipse-mosquitto:2
    restart: unless-stopped
    ports:
      - 1883:183

where chirpstack and chirpstack-gateway-bridge both have a dependency on mosquitto.

I then do a

docker-compose down

followed by a

docker-compose up -d

The gateway on the chirpstack gui shows offline

This is the MQTT integration section ^ within your Chirpstack.toml, this is where Chirpstack forwards events after processing them, it is not where it looks for incoming data itself.

If you look at the full configuration options: Configuration - ChirpStack open-source LoRaWAN® Network Server documentation

You can find that the Chirpstack MQTT backend is actually in the regional .toml files.

The lines look like:

      # MQTT configuration.
      [regions.gateway.backend.mqtt]

        # Event topic template.
        event_topic="eu868/gateway/+/event/+"

        # Command topic template.
        command_topic="eu868/gateway/{{ gateway_id }}/command/{{ command }}"

        # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
        server="tcp://localhost:1883"

The first thing you should do to diagnose issues like this is look at the logs:

docker-compose logs -f

Where Chirpstack would have been throwing errors about the MQTT connection, which would have lead you to realize something was still amiss with its connection.