MQTT in Docker setup trouble

I ran the following command to create the container:

sudo docker run -d --name=mqtt --restart=unless-stopped --user="root" -p 1885:1883 -p 9004:9001 -v /home/admin/mqtt/config:/mqtt/config -v /home/admin/mqtt/data:/mqtt/data -v /home/admin/mqtt/log:/mqtt/log -e PGID=1000 -e PUID=1000 -e UMASK_SET=000 eclipse-mosquitto

When trying to connect from HA, I configured the ip of the machine and port 1883, no authentication, and it fails to connect.

Your command line exposes port 1885 from the container and not 1883. Is that a typo?

I picked that up from this thread: How to install and configure eclipse mqtt docker - #5 by morpheusnow

I did try it as 1883:1883 and 9001:9001. That did not work either.

How you install HA? Same machine in docker?

If so I suggest using the containers hostname instead of it’s IP. Hostname is more reliable and flexible from within docker network(another docker container in environment)I will verify term and edit this)

I think 9001 is websockets so not sure how changing it affect connection.

Portainer is good to use when managing docker containers. You can look at logs there and verify some failures or quickly modify things. If using already check the container logs or just connect inside HA container and try to ping mosquitto.


Forgot to ask, is mosquitto running? How you verify the container started?

HA installed in another container on the same machine.

I need to have the mqtt broker accessible from other machines.

I’ll check out portainer.

Verified mosquitto status using docker ps -a.

Portainer is awesome!

So this is all I have for logs in mosquitto:

1665497642: mosquitto version 2.0.15 starting
1665497642: Config loaded from /mosquitto/config/mosquitto.conf.
1665497642: Starting in local only mode. Connections will only be possible from clients running on this machine.
1665497642: Create a configuration file which defines a listener to allow remote access.
1665497642: For more details see
1665497642: Opening ipv4 listen socket on port 1883.
1665497642: Opening ipv6 listen socket on port 1883.
1665497642: Error: Address not available
1665497642: mosquitto version 2.0.15 running

It mentions creating a config file for remote access. There is a file in root for unauthenticated access. Is it referring to a different file?

Ok. So it looks like I need to do some configuration in the mosquitto.conf file. I’ve tried setting per_listener_settings true, and setting allow_anonymous true. That did not work. I then tried setting listener 1883 <machine ip>. No dice. I’m not quite sure which settings I need to change.

I think the issue is the line that say Error: Address not available. Readimg the below github issue, i think this relates to your problem as v2.x has restrictions to bind to the loopback interface if no interface specified in the listener. Hope you can figure it out from this.

Ok, I got it.

I needed to set the following settings in mosquitto.conf:

listener 1883
persistance true
persistance_location /mosquitto/data/
allow_anonymous true

After I changed those settings, it still didn’t work because I was trying to connect to 1885. The setup command I used mapped it to 1885. So I went back in and changed those mappings. so now it works.

This is the command to use for those looking for help:

sudo docker run -d --name=mqtt --restart=unless-stopped -p 1883:1883 -p 9001:9001 -v /home/admin/mqtt/config:/mqtt/config -v /home/admin/mqtt/data:/mqtt/data -v /home/admin/mqtt/log:/mqtt/log -e PGID=1000 -e PUID=1000 -e UMASK_SET=000 eclipse-mosquitto

Make sure you create the directories before you run the command. You can locate them wherever you wish, and you can change the --name= to whatever you want.

An alternative is to use portainer. I came across this tutorial that looks like it’s much easier that way.


I was referring to connections from within docker only.

Glad you got setup.

Do you actually use PUID and GUID?

Do you actually use PUID and GUID?

Probably not.