No connection to Mosquitto with localhost (Docker)

First of all, I must apologize, as this topic is most likely not directly related to Node-RED, but to Docker. But maybe you guys can help me anyway.

Node-RED is natively installed on a Raspberry Pi.
In parallel, an instance of Mosquitto is running in a Docker container.

I was always able to access the Mosquitto MQTT broker with localhost.

But after I had to completely rebuild the RPi, the connection only works via the real IP, i.e. 192.168.0.10 instead of also via localhost.
Unfortunately, I have absolutely no idea whether I have made a special setting for this, or whether this had worked out of the box.

I would rather not run the container on the network "host" on Docker.
This would allow me to address Mosquitto via localhost, but I'm sure I hadn't done it that way before the reinstall.

I would be very grateful for any tips and tricks.

Thanks a lot
Newbow

Why run mosquitto in a container in the first place... ?

Well, I thought this is the best way to handle updates.
I have serveral container and it's way easier to move/ clone container to another machine.

I just tried the IP 127.0.0.1 and it works... But why does it not work when using the word "localhost"? It used to work earlier. I don't get it.

What is in the file /etc/hosts?

This is my /etc/hosts:

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 raspberrypi

In that case localhost should map to 127.0.0.1, so I don't know why that would not work. I suspect it is to do with the way the docker container is setup, but I don't know what. Unless it is an ipv6 issue.

Thank you Colin, you have put me on the right track.

I changed/ commented my /etc/hosts file as follows:

127.0.0.1 localhost
#::1 localhost ip6-localhost ip6-loopback
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters
127.0.1.1 raspberrypi

I read somewhere that especially the localhost in the line:
::1 localhost ip6-localhost ip6-loopback causes problems.
Now it's working like a charm again. Maybe the ip6 crap got in my way :wink:

grafik

grafik

EDIT:
By the way, this also works (removing just the localhost in the second line):

127.0.0.1 localhost
#::1 localhost ip6-localhost ip6-loopback
::1 ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 raspberrypi

1 Like

Normally what you have would work. Perhaps your docker container is not able to receive IPV6.

we have seen/heard of several issue with DNS and IPv6 on docker on Alpine builds (that we use).

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