Cant connect to MQQT docker


I am running HA in docker, and I was able to start MQTT docker as well. I can see its running, in the logs.

1715966862: Opening ipv4 listen socket on port 1883.
1715966862: Opening ipv6 listen socket on port 1883.

If I try to connect to connect to port 1883 via telnet from any device on the network it seems to work:

1715969223: New connection from on port 1883.
1715969227: Client <unknown> disconnected due to protocol error.

But when I try to integrate MQTT into HA, and I input the IP adress, nothing happens. After a while I get an Unknown error message and thats it.

Also what I find strange that all the connection I make are coming from according to mosquitto log. I think this is the IP adress of my HA instance.

Any ideas?

Create hostname for your container and use the hostname and docker network for connection. Anything else won’t work or will be a mess.

You need to study how docker networking works. Docker creates its own network. Connections from a container will originate from the docker network. You may also create your own docker networks. These networks may be used for container to container connections. You should be using these networks for container to container connections. You should not use the docker IPs unless necessary as they will be changed and will not survive a rebuild

Instead you should give your containers a hostname and use that.