Escher
Escher

Reputation: 5776

Unable to connect to the Eclipse Mosquitto image

I am unable to reach my Mosquitto server from the client container, and I don't know why.

Here's an extract from the docker-compose.yml:

version: '3.3'
services:
   wd_mosquitto:
     image: eclipse-mosquitto:latest
     container_name: wd-mosquitto
     ports:
       - 1883:1883

   wd_message_client:
     image: wd_message_client_image
     container_name: wd-message-client
     ports:
       - 1883:1883
     external_links:
       - wd_mosquitto
     depends_on:
       - wd_mosquitto

Here's what I get trying to subscribe to the broker from inside the client container docker exec -it wd-message-client /bin/bash

root@72f57bdda570:/code# mosquitto_sub -h "test.mosquitto.org" -t "#" -C 3
{ replies from the test server that confirm mosquitto_sub works }

root@72f57bdda570:/code# mosquitto_sub -h "tcp://wd-mosquitto:1883" -t "#" -C 3
Unable to connect (Lookup error.).

root@72f57bdda570:/code# ping wd-mosquitto
PING wd-mosquitto (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: icmp_seq=0 ttl=64 time=0.112 ms 

Good, mosquitto_sub works and I can resolve and ping the Mosquitto container, but can't subscribe to the broker.

Here are the results of me fiddling in the Mosquitto container with docker exec -it wd-mosquitto /bin/sh (bash isn't available)

/ # ps
PID   USER     TIME   COMMAND
    1 mosquitt   0:00 /usr/sbin/mosquitto -c /mosquitto/config/mosquitto.conf
    6 root       0:00 /bin/sh
   12 root       0:00 ps

/ # mosquitto
1521984736: mosquitto version 1.4.12 (build date 2017-06-01 13:03:46+0000) starting
1521984736: Using default config.
1521984736: Opening ipv4 listen socket on port 1883.
1521984736: Error: Address in use

/ # mosquitto_sub -t "$SYS"
/bin/sh: mosquitto_sub: not found

OK, I guess mosquitto_sub isn't included on the docker image, but I can confirm that Mosquitto is running on port 1883. Why isn't it reachable? I haven't specified a config file, so it should allow anonymous connections.

Any ideas?

Upvotes: 1

Views: 6812

Answers (1)

jrtapsell
jrtapsell

Reputation: 7001

Issue with ports

At the moment you map both container ports to the same host port, which may cause some weird issues. As from the container you can talk to any container port directly you do not need to fix the host port too.

How to fix

You can replace the lines like this:

- 1883:1883

with:

- 1883

Visual

Before:

enter image description here

After:

enter image description here

Upvotes: 1

Related Questions