# Can't connect to Mosquitto MQTT broker running on my localhost 1883

**URL:** <https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300>\
**Category:** Dashboard\
**Tags:** node-red-dashboard, mqtt\
**Created:** [20 October 2022 06:06 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300 "2022-10-20T06:06:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kushpatel](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@kushpatel](https://discourse.nodered.org/u/kushpatel)\
**Post date:** [20 October 2022 06:06 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/1 "2022-10-20T06:06:37Z")

</div>

Currently I'm running Node-RED using docker on my local system with **"docker run -it -p 1880:1880 -v D:/ABOS/Node-RED/data:/data --name local-node-red nodered/node-red"** command and it executed successfully and also I can open node-RED on [http://localhost:1880/](http://localhost:1880/).

I have also started Mosquitto MQTT broker with default setting on my local system on port 1883.  
I tried to subscribe and publish message to this broker using mosquitto commands and it works perfectly.

Now when I try to connect to that Mosquitto Broker using **MQTT In** and **MQTT Out** node , those node can't connect to that broker.  
I'm attaching Mqtt Nodes configuration and error that I get in node-RED.

 ![broker_property_setting](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd208c6eab02db152e8e4ad4536f9eefa1c9a7a8.jpeg)  
 ![mqtt_in_node_configuration](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a1e66295b2f4388f36857950e3df12c9ebd9299.jpeg)  
 ![error_in_node_red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/22c1cdf0ed34d71d48eb86fcf3237a48fd608bbf.jpeg)

Please help me to connect to that mosquitto mqtt broker running on my localhost.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [20 October 2022 07:04 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/2 "2022-10-20T07:04:55Z")

</div>

It is important to understand that when an application runs in a container it gets its own TCP/IP stack.

That means that 127.0.0.1/localhost will point to that dedicated stack inside the container, not the host machine.

Docker sets up a virtual network that all containers and the host live on. By default the host address will be 172.17.0.1

(You will need to also ensure that mosquitto is set up to allow connections on addresses other than 127.0.0.1/localhost by adding a new listener and probably allowing anonymous connections)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 October 2022 19:32 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/3 "2022-10-20T19:32:28Z")

</div>

If the broker is on the host machine you may just need to open that port on your container by adding `-p 1883:1883` to your launch command

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [20 October 2022 21:12 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/4 "2022-10-20T21:12:02Z")

</div>

Err no, that worked only be if the broker is in another container...

---

<div class="post-metadata">

**Author:** ![Falfango](https://avatars.discourse-cdn.com/v4/letter/f/5e9695/32.png) [@Falfango](https://discourse.nodered.org/u/Falfango)\
**Post date:** [21 October 2022 10:08 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/5 "2022-10-21T10:08:47Z")

</div>

Depends if the docker runs as bridge or host. I assume, that it is in bridge. then you have to do portforwarding. You can also try to run it as host, then it whould work with youre settings.

---

<div class="post-metadata">

**Author:** ![jackxuhass](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jackxuhass/32/70023_2.png) [@jackxuhass](https://discourse.nodered.org/u/jackxuhass)\
**Post date:** [7 November 2022 07:00 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/6 "2022-11-07T07:00:06Z")

</div>

You must connect host ip!!! 192.168.XXX  
not 127.0.0.1 (container ip)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 December 2022 07:00 UTC](https://discourse.nodered.org/t/cant-connect-to-mosquitto-mqtt-broker-running-on-my-localhost-1883/69300/7 "2022-12-07T07:00:57Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
