1

I'm trying to setup mqtt broker in a Docker container. I pulled the following Docker image (https://hub.docker.com/_/eclipse-mosquitto) on my machine and I can successfully launch the Docker container with the following command:

 docker run -it -p 1883:1883 -p 9001:9001 --network=host eclipse-mosquitto

If I run it with that command I get the following output:

WARNING: Published ports are discarded when using host network mode
1616081533: mosquitto version 2.0.9 starting
1616081533: Config loaded from /mosquitto/config/mosquitto.conf.
1616081533: Starting in local only mode. Connections will only be possible from clients running on this machine.
1616081533: Create a configuration file which defines a listener to allow remote access.
1616081533: Opening ipv4 listen socket on port 1883.
1616081533: Opening ipv6 listen socket on port 1883.
1616081533: mosquitto version 2.0.9 running

So then I start Mqttfx and I set up a connection to 127.0.0.1 and port 1883 but the MQTT client is unable to connect to my broker. What am I doing wrong?

hardillb
  • 54,545
  • 11
  • 67
  • 105
John
  • 728
  • 2
  • 15
  • 37

1 Answers1

2

Okay, let's read those logs :

WARNING: Published ports are discarded when using host network mode

In host mode, the ports exposed by the container are directly accessible from your local machine IP (the container uses your host machine IP address). So you do not need the -p option when launching the container

1616081533: Starting in local only mode. Connections will only be possible from clients running on this machine.

1616081533: Create a configuration file which defines a listener to allow remote access.

It seems that you need to change some configurations for Mosquitto : creating a mosquitto.conf file and looking more precisely at options like bind_addressand listeners

You can find more about that here and here

Faeeria
  • 786
  • 2
  • 13
  • Do you think this is necessarily in my case? Because I just want to access the broker at this stage locally. So the docker image is on the same machine where I want to access it. – John Mar 18 '21 at 16:09
  • Yes this is required, because mosquitto in the container is effectively on a different (virtual) machine – hardillb Mar 18 '21 at 16:10