Search code examples
dockermqttmosquitto

Eclipse-mosquitto "Address not available"


I am new to mqtt and am trying to simply start a local instance with which I can test.

When executing

docker run -it -p 1883:1883 --restart always -v mosquitto.conf:/home/juliette/mosquito.conf --name mqtt eclipse-mosquitto:2.0.7

I get the following output:

1615963221: mosquitto version 2.0.7 starting
1615963221: Config loaded from /mosquitto/config/mosquitto.conf.
1615963221: Starting in local only mode. Connections will only be possible from clients running on this machine.
1615963221: Create a configuration file which defines a listener to allow remote access.
1615963221: Opening ipv4 listen socket on port 1883.
1615963221: Opening ipv6 listen socket on port 1883.
1615963221: Error: Address not available
1615963221: mosquitto version 2.0.7 running

and cannot connect with a mqtt-client:

mqtt sub --topic test
Server closed connection without DISCONNECT.

From what I've found the error apparently happens when no listener is configured but I did configure one, this is my mosquito.conf:

listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
port 1883

I also tried changing the port to 8883 because in one post someone mentioned that a larger port might solve the problem but that also didn't work.

Can someone tell me what I'm doing wrong?


Solution

  • Your startup command is close, but not correct. It should be:

    docker run -it \
      -p 1883:1883 \
      --restart always \
      -v /home/juliette/mosquito.conf:/etc/mosquitto/mosquitto.conf \
      --name mqtt \
      eclipse-mosquitto:2.0.7
    

    The config file is in /etc/mosquitto...unless they have moved it in version 2.

    You might also want to add a -p 8333:8333 line for mqtts/TLS connections.

    EDIT: I see up in your log file output it says that the config was loaded from /mosquitto/config/mosquitto.conf ...so if the -v /home/juliette/mosquito.conf:/etc/mosquitto/mosquitto.conf line does not work, change it to -v /home/juliette/mosquito.conf:/mosquitto/config/mosquitto.conf