Use the integration
HA >> settings >> devices and services >> add integration >> mqtt
When connecting docker containers I use the host name of container as this prevents issues if docker decides to change the docker IP. By using this method you only need expose ports if connecting outside docker network
You can use portainer to set hostame if you did not do so during container creation
EDIT
If it is not clear, the integration will connect to the mosquitto container you setup.