Auto-configure MQTT broker in HA (Docker)

Bit of a beginner to Docker, so please bare with me.

When I restart my server and docker comes up again, the container IPs change.
I want to not always have to go into Home Assistant and “Reconfigure” MQTT to the new IP. Is there a way, when starting all the containers, Home Assistant to know that MQTT broker container is at IP x.x.x.x and just pick it up automatically?


I’m not a docker specialist, but I think if you specify all your dockers in the same docker-compose.yaml, you can use the docker name instead of the IP.

Set hostname for your docker containers.

You will use hostname for connecting instead of ip.

You must also ensure they are in same docker network. If you don’t create docker networks they will use default so they will all be in same network