# NODE-RED and MOSQUITTO docker-compose

**URL:** <https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904>\
**Category:** General\
**Created:** [2 March 2021 15:53 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904 "2021-03-02T15:53:08Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [2 March 2021 15:53 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/1 "2021-03-02T15:53:08Z")

</div>

Hi,  
I've googled looking for docker compose with node-red and mosquitto, but I can't use properly.  
Someone has the example?

Thanks

---

<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:** [2 March 2021 19:59 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/2 "2021-03-02T19:59:55Z")

</div>

this works for me

```auto
services:
  node-red:
    image: nodered/node-red:latest
    restart: unless-stopped
    environment:
      - TZ=Europe/London
    networks:
      - node-red-net
    ports:
      - "1880:1880"
    volumes:
      - node-red-data:/data

  MQTTbroker:
    image: eclipse-mosquitto:1.6.13
    restart: unless-stopped
    networks:
      - node-red-net

volumes:
  node-red-data:

networks:
  node-red-net:

```

---

<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:** [2 March 2021 21:43 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/3 "2021-03-02T21:43:19Z")

</div>

Hi @dceejay  
Thaks a lot for share.

what broker server ip did you insert into connection tab of mqtt broker?

in my case never shown connected. 🙁

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/858a16b72b057af1d277309c0b725dc8a191277d.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/220407a00af556ea0a902b1cc9a828bc2ff50d67.png)

---

<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:** [2 March 2021 22:59 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/4 "2021-03-02T22:59:26Z")

</div>

The name it was called in the compose file. MQTTbroker

---

<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:** [3 March 2021 10:54 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/5 "2021-03-03T10:54:56Z")

</div>

I'm facing the same status from mqtt node "conecting".

- I've tagged my MQTTbroker services to version 1.6.13 on docker compose file;
- and tryied service name (MQTTbroker, localhost, container IP) for mqtt connection

none of above options succed. ☹

---

<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:** [3 March 2021 11:23 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/6 "2021-03-03T11:23:27Z")

</div>

can you get a terminal session into the node-red container and then try pinging the other.  
I use Portainer to manage them so it's easy but command line like

```auto
docker exec -it cp_node-red_1 /bin/bash

```

should work

where `cp_node-red_1` comes from when you do `docker-compose up` and get

```auto
$ docker-compose up
Starting cp_MQTTbroker_1 ... done
Starting cp_node-red_1 ... done
Attaching to cp_MQTTbroker_1, cp_node-red_1

```

---

<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:** [3 March 2021 11:41 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/7 "2021-03-03T11:41:35Z")

</div>

Nice @dceejay.  
I did exactly what you said and it works for me also.

I tried remake the step-by-step of mosquitto configuration, but this turn I switched anonimous false to anonimous true and got connected.  
Do you know how could I secure mqtt connection?  
I used the tutorial (method 1) below. Do you have any concerns?

Thanks a lot for all help until here.

> **[Mosquitto Username and Password Authentication -Configuration and Testing](http://www.steves-internet-guide.com/mqtt-username-password-example/)**
>
> How to connect to an MQTT broker that requires authentication using a username and password. What happens when username or passwords are invalid.

---

<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:** [2 May 2021 11:41 UTC](https://discourse.nodered.org/t/node-red-and-mosquitto-docker-compose/41904/8 "2021-05-02T11:41:35Z")

</div>

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