# Mosquitto on Docker inaccessible from local network (even with "allow\_anonymous true")

**URL:** <https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445>\
**Category:** Deployment\
**Created:** [January 24, 2022, 4:30pm UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445 "2022-01-24T16:30:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElectroDad](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@ElectroDad](https://forum.cedalo.com/u/ElectroDad)\
**Post date:** [January 24, 2022, 4:30pm UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/1 "2022-01-24T16:30:55Z")

</div>

I cannot connect to my mosquitto container from the local network. I’m able to sub or pub to my MQTT broker from within the docker container but cannot connect from other machines on the local network. I have adjusted the security settings for mosquito 2.x. My mosquito.config file looks like this:

> listener 1883  
> allow\_anonymous true

My docker \_compose file looks like this (the html formatting is stripping the indents):

> version: ‘3.8’
> 
> services:  
> mqtt:  
> image: eclipse-mosquitto  
> container\_name: mosquitto-container  
> restart: always  
> ports:  
> - “1883:1883”  
> - “9001:9001”  
> - “8883:8883”  
> volumes:  
> - /volume1/Docker/IOT/Mosquitto/config:/mosquitto/config  
> - /volume1/Docker/IOT/Mosquitto/data:/mosquitto/data  
> - /volume1/Docker/IOT/Mosquitto/log:/mosquitto/log

Should I add the IP address of the server (192.168.2.102) to the “listener” line in the conf file? I have not seen this in any examples. The examples all just show the port number (1883).

When I _sudo docker exec -it mosquitto-container /bin/ash_ to open a shell in the container, I can successfully issue mosquitto\_sub and mosquitto\_pub commands. If I modify the config file and create a passwords file, I can successfully issue authenticated pub and sub commands with the appropriate -u and -P options but only from within the docker instance. If I try from other devices (an IOT device or a different machine running MQTT Explorer), they just do not connect.

Other docker containers (Home Assistant and Rcon) work fine on the local network. When testing with MQTT Explorer, there is a long delay before a timeout when I try to connect to the correct port (1883) but an instant fail when try to connect to wrong port (1890). I assume this means something is trying to happen as the connections is not immediately refused.

I’m a bit over my head and I really do not know how to trouble shoot from here. Any help very much appreciated.

My Docker session is running on an Asustor AS5304T NAS (Busybox) and I am administering via Portainer with SSH access for pub/sub commands and config file editing.

---

<div class="post-metadata">

**Author:** ![roger.light](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@roger.light](https://forum.cedalo.com/u/roger.light)\
**Post date:** [January 25, 2022, 11:58am UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/2 "2022-01-25T11:58:41Z")

</div>

Hi,

All of what you’ve said looks fine, can I just check that your config file is `mosquitto.conf` and is in `/volume1/Docker/IOT/Mosquitto/config` ?

Cheers,

Roger

---

<div class="post-metadata">

**Author:** ![ElectroDad](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@ElectroDad](https://forum.cedalo.com/u/ElectroDad)\
**Post date:** [January 25, 2022, 4:02pm UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/3 "2022-01-25T16:02:19Z")

</div>

Roger,  
thank you for taking time to consider my conundrum. I’m glad to see I hadn’t made any glaring errors.  
I rebooted the actual server for a minor server software update and to my surprise, when I checked the mqtt logs, the data was coming through! 😀

I can only assume it was the reboot as I didn’t check the logs prior to the update and I doubt it was the server software. I had turned off the log file in the interest of simplicity for troubleshooting so I can’t see when things got back on the rails. It is nice the problem is solved but I would much rather know what the problem was and that it is fixed. -Oh well.

Thanks again. Nice to know there are people like you willing to help people like me as they are beginning their journey.

---

<div class="post-metadata">

**Author:** ![roger.light](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@roger.light](https://forum.cedalo.com/u/roger.light)\
**Post date:** [January 25, 2022, 5:10pm UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/4 "2022-01-25T17:10:32Z")

</div>

Great! I’m glad it got sorted out even if we don’t quite know why.

---

<div class="post-metadata">

**Author:** ![tfmeier](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.cedalo.com/tfmeier/32/457_2.png) [@tfmeier](https://forum.cedalo.com/u/tfmeier)\
**Post date:** [June 8, 2022, 1:37am UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/5 "2022-06-08T01:37:07Z")

</div>

I may have a similar issue. I’m running mosquitto in Docker (new to Docker, coming from Home Assistant) but chose to migrate as I have a few Home Assistant instances so running the MQTT broker away from Home Assistant means I don’t have to change MQTT broker addresses.

Anyway looking at portainer the container seems to be running

 ![mosquitto in portainer](https://canada1.discourse-cdn.com/flex030/uploads/streamsheets/original/1X/245c28f4765bb23f8141353bc66422081b1c66c3.png)

but the log file doesn’t show any startup, listening events etc. other than that 'port’s will be replaced with ‘listener’. I see this is a warning of a future change.

```auto
1654644103: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654644156: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654644420: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654644713: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654645649: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654650172: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.
1654651376: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.

```

`mosquitto.conf` is in the folder specified below. What is strange is the owner of the file

```auto
[root@mqtt-broker portainer]# ls /home/themeierresidence/mosquitto/config -al
total 4
drwxr-xr-x. 2 themeierresidence themeierresidence 28 Jun 8 11:19 .
drwxr-xr-x. 5 themeierresidence themeierresidence 43 Jun 8 09:28 ..
-rwxrwxrwx. 1 1883 1883 3735 Jun 8 09:46 mosquitto.conf

```

and that’s why I temporarily changed the access to 777

`docker-compose.yaml` looks like this

```auto
  mosquitto:
    image: eclipse-mosquitto
    container_name: mosquitto
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - /home/themeierresidence/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
      - /home/themeierresidence/mosquitto/data:/mosquitto/data
      - /home/themeierresidence/mosquitto/log:/mosquitto/log
~

```

Any idea what could be going on here?

---

<div class="post-metadata">

**Author:** ![tfmeier](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.cedalo.com/tfmeier/32/457_2.png) [@tfmeier](https://forum.cedalo.com/u/tfmeier)\
**Post date:** [June 13, 2022, 2:05am UTC](https://forum.cedalo.com/t/mosquitto-on-docker-inaccessible-from-local-network-even-with-allow-anonymous-true/445/6 "2022-06-13T02:05:45Z")

</div>

In case anyone is experiencing the same issue I was able to solve this by adding the following line to `mosquitto.conf`

`listener 1883`

I thought the log message `1654644156: The 'port' option is now deprecated and will be removed in a future version. Please use 'listener' instead.` was a bit confusing but anyway this solved it…
