Container cannot connect to port 1883 even on the same network

These three containers are running and communicating with each other just fine.

PS C:\BRIDGE> docker ps
CONTAINER ID   IMAGE                             COMMAND                  CREATED       STATUS       PORTS                                                                       NAMES
667c6d8c6ac1   cedalo/management-center:2        "docker-entrypoint.s…"   2 hours ago   Up 2 hours   0.0.0.0:8088->8088/tcp                                                      broker_management-center_1
f7a24853b1b4   cedalo/streamsheets:2-milestone   "docker-entrypoint.s…"   2 hours ago   Up 2 hours   1883/tcp, 6379/tcp, 8080/tcp, 8083/tcp, 27017/tcp, 0.0.0.0:8081->8081/tcp   broker_streamsheets_1
92ad0f83f778   eclipse-mosquitto:2-openssl       "/docker-entrypoint.…"   2 hours ago   Up 2 hours   0.0.0.0:1883->1883/tcp                                                      broker_mosquitto_1

Performing inspect shows they are all running through a network called “cedalo-platform” (output shown at end of this message)

> docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
098da67fe363   bridge            bridge    local
3302dd7e3329   cedalo-platform   bridge    local
2b748a0a31c8   host              host      local
069a6a05126f   none              null      local
c163d8ad4267   todo-app          bridge    local

I then start up a container for a gateway-bridge.The docker-compose yaml specifies that it should be on the cedalo-platform network and that this network is external. Despite whether I use tcp://0.0.0.0:1883 or if I used tcp://127.0.0.1:1883 neither of these will connect. In fact the error that appears (“connection refused”) is identical as if I had not even started the above three containers. It is as if it cannot see this port at all.

Try 0.0.0.0 connection refused.

[+] Running 1/0
 - Container bridge-lora-bridge-1  Created                                                                                                                                                0.0s
Attaching to bridge-lora-bridge-1
bridge-lora-bridge-1  | INFO[0000] starting ChirpStack Gateway Bridge            docs="https://www.chirpstack.io/gateway-bridge/" version=
bridge-lora-bridge-1  | INFO[0000] backend/semtechudp: starting gateway udp listener  addr="0.0.0.0:1700"
bridge-lora-bridge-1  | ERRO[0000] [client]   dial tcp 0.0.0.0:1883: connect: connection refused  module=mqtt
bridge-lora-bridge-1  | WARN[0000] [client]   failed to connect to broker, trying next  module=mqtt
bridge-lora-bridge-1  | ERRO[0000] [client]   Failed to connect to a broker      module=mqtt
bridge-lora-bridge-1  | FATA[0000] network Error : dial tcp 0.0.0.0:1883: connect: connection refused
bridge-lora-bridge-1 exited with code 1

Trying 127.0.0.1 connection refused

[+] Running 1/0
 - Container bridge-lora-bridge-1  Created                                                                                                                                                0.0s
Attaching to bridge-lora-bridge-1
bridge-lora-bridge-1  | INFO[0000] starting ChirpStack Gateway Bridge            docs="https://www.chirpstack.io/gateway-bridge/" version=
bridge-lora-bridge-1  | INFO[0000] backend/semtechudp: starting gateway udp listener  addr="0.0.0.0:1700"
bridge-lora-bridge-1  | ERRO[0000] [client]   dial tcp 127.0.0.1:1883: connect: connection refused  module=mqtt
bridge-lora-bridge-1  | WARN[0000] [client]   failed to connect to broker, trying next  module=mqtt
bridge-lora-bridge-1  | ERRO[0000] [client]   Failed to connect to a broker      module=mqtt
bridge-lora-bridge-1  | FATA[0000] network Error : dial tcp 127.0.0.1:1883: connect: connection refused
bridge-lora-bridge-1 exited with code 1

This is the YAML that I am using showing cedalo-platform and listed external.

version: "3.6"
services:
  lora-bridge:
    image: chirpstack/chirpstack-gateway-bridge
    stdin_open: true # docker run -i
    tty: true  # docker run -t
    privileged: true
    volumes: 
      - C:\BRIDGE\.config:/etc/chirpstack-gateway-bridge/
    networks:
      - cedalo-platform
      
networks:
    cedalo-platform:
       name: cedalo-platform
       driver: bridge
       external: true

The following is further proof that the three containers are bundled into the network called cedalo-platform I am completely stuck and need any advice to proceed.

> docker inspect 92ad0f83f778
    "Networks": {
                "cedalo-platform": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "92ad0f83f778",
                        "mosquitto"
                    ],
                    "NetworkID": "3302dd7e3329fc220380928c7d4b369d7ba72ee82d7a5b543a301c936d0e499f",
                    "EndpointID": "bfbda12ca73510d9c8c3de7e38e3b191ee98e74a7e4b0232504c5c24c003f674",
                    "Gateway": "172.21.0.1",
                    "IPAddress": "172.21.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:15:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
>docker inspect f7a24853b1b4 
"Networks": {
                "cedalo-platform": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "f7a24853b1b4",
                        "streamsheets"
                    ],
                    "NetworkID": "3302dd7e3329fc220380928c7d4b369d7ba72ee82d7a5b543a301c936d0e499f",
                    "EndpointID": "bc4f73c6760026f5715a77e5d331f751c06c8be962578803b410b71408223e85",
                    "Gateway": "172.21.0.1",
                    "IPAddress": "172.21.0.4",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:15:00:04",
                    "DriverOpts": null
                }
            }
>docker inspect 667c6d8c6ac1
 "Networks": {
                "cedalo-platform": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "management-center",
                        "667c6d8c6ac1"
                    ],
                    "NetworkID": "3302dd7e3329fc220380928c7d4b369d7ba72ee82d7a5b543a301c936d0e499f",
                    "EndpointID": "d54a2f929df2a7aa49b152ccb2d4a46246f6f5ed6191a12249f5000154fbbdbf",
                    "Gateway": "172.21.0.1",
                    "IPAddress": "172.21.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:15:00:03",
                    "DriverOpts": null
                }
            }

Hi, you need to define the broker container ip, eventhough its a container, each instance still have its own IP.
0.0.0.0 is not valid here, and 127.0.0.1 will just try and connect to itself.

Try setting it to “broker_mosquitto”, instead, then it will try and get the ip from the hostname.