Setting up more than one MQTT broker with Docker -


using docker, able use eclipse-mosquitto set mqtt broker app, subscribes messages. i'm learning docker right now, wanted try adding 2 brokers docker-compose different ports mapped this:

version: '3' services:   myapp:     ...     links:       - mqtt       - mqtt2     depends_on:       - mqtt       - mqtt2   mqtt:     image: eclipse-mosquitto:latest     container_name: mqtt-iot     ports:       - 1883:1883    mqtt2:     image: eclipse-mosquitto:latest     container_name: mqtt2-iot     ports:       - 1884:1883 

from outside of myapp container (i.e. os x terminal), both mqtt , mqtt2 working; can publish , subscribe messages expected.

const mqtt = require('mqtt') mqtt.connect('mqtt://mqtt', {port: 1883}) // success mqtt.connect('mqtt://mqtt2', {port: 1884}) // success 

however, when i'm inside container of myapp, can connect mqtt. mqtt2 connection fires offline event right away, , no connection fails. need myapp using both of brokers properly?

two issues here

links:   - mqtt   - mqtt2 

links deprecated , not required in compose. next when use below

const mqtt = require('mqtt') mqtt.connect('mqtt://mqtt', {port: 1883}) // success mqtt.connect('mqtt://mqtt2', {port: 1884}) // success 

from outside. based on ports on host. when app container should below

const mqtt = require('mqtt') mqtt.connect('mqtt://mqtt', {port: 1883}) // success mqtt.connect('mqtt://mqtt2', {port: 1883}) // success 

the container cannot see mapped port on host. see inside network. , in local network both listen on 1883


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -