# Mqtt Docker not able to connect

**URL:** <https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084>\
**Category:** General\
**Created:** [16 February 2021 11:41 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084 "2021-02-16T11:41:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranavthakkar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@pranavthakkar](https://discourse.nodered.org/u/pranavthakkar)\
**Post date:** [16 February 2021 11:41 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/1 "2021-02-16T11:41:28Z")

</div>

Hello, I'm new to docker. and wanted to communicate two containers. so I used this approach instead of making a new compose file. [Linking Containers](https://nodered.org/docs/getting-started/docker#linking-containers).

but I'm not able to connect my MQTT node with a broker. I have not assigned global port 1883.

here is NR docker log.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac00963f6497cf47f38027505081fd54114d63ca.png)

P.S: other than this I have not done anything like making mosquitto.conf file or moving[cp] to container. I only done this as shown above link. Am i missing something?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2021 21:14 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/2 "2021-02-16T21:14:13Z")

</div>

localhost means local (i.e. inside the docker) - where is the broker running? In the same container? or a separate container? or on the host? or on an external machine?

Change `localhost` to the IP of the container/host/external PC

---

<div class="post-metadata">

**Author:** ![pranavthakkar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@pranavthakkar](https://discourse.nodered.org/u/pranavthakkar)\
**Post date:** [17 February 2021 03:17 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/3 "2021-02-17T03:17:27Z")

</div>

Broker running on a separate container. as I said I exactly done this way [Linking container](https://nodered.org/docs/getting-started/docker#linking-containers).

I tried to change localhost to broker container name

> "mybroker"

. but doesn't work. how can I get the IP of that container?

---

<div class="post-metadata">

**Author:** ![pranavthakkar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@pranavthakkar](https://discourse.nodered.org/u/pranavthakkar)\
**Post date:** [17 February 2021 04:00 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/4 "2021-02-17T04:00:34Z")

</div>

I check the `container: mybroker` IP address by `docker inspect`. and get the 172.20.0.3.

Still not able to connect.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0831eae03fd53da48bcc6c92108caba24e6044d3.png)

Also, I got inside of my container where NR is running. and on that, I'm pinging the broker container I got the result. but don't know why it is not able to connect.

![pingbroker](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/852426eac3669e44254ee7d80ccac935d11fb13c.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 February 2021 04:37 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/5 "2021-02-17T04:37:39Z")

</div>

This is a common docker issue. Search Google for docker to docker communication. There are lots of answers.

Question. Why use docker?

---

<div class="post-metadata">

**Author:** ![henrycosta05](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrycosta05/32/36350_2.png) [@henrycosta05](https://discourse.nodered.org/u/henrycosta05)\
**Post date:** [17 February 2021 05:34 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/6 "2021-02-17T05:34:24Z")

</div>

Hi @pranavthakkar ,  
Are you sure both containers are in the same network?  
Also for the mosquitto container you would configure the config, data and log folder to run  
properly.

> **[jllopis/docker-mosquitto](https://github.com/jllopis/docker-mosquitto)**
>
> Mosquitto MQTT Broker on Docker Image. Contribute to jllopis/docker-mosquitto development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![pranavthakkar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@pranavthakkar](https://discourse.nodered.org/u/pranavthakkar)\
**Post date:** [17 February 2021 08:25 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/7 "2021-02-17T08:25:22Z")

</div>

Thank you @Steve-Mcl. I got a solution by putting its IP. the default IP docker0 is always connect to the broker. and if I put the new NETWORK IP(IoT) not the `broker IP` then it is work.

Right now I'm exploring docker. what I want is to make my own image out of it and use it for scale.

---

<div class="post-metadata">

**Author:** ![pranavthakkar](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@pranavthakkar](https://discourse.nodered.org/u/pranavthakkar)\
**Post date:** [17 February 2021 08:26 UTC](https://discourse.nodered.org/t/mqtt-docker-not-able-to-connect/41084/8 "2021-02-17T08:26:47Z")

</div>

Hi @henrycosta05 . thing is I have not added any config file to Mosquitto container. but yes it is solved.

Thanks for your reply
