I'm updatet my mosquitto from v1.6.9 to v2.0.12. But now, I'm not able to send mqtt messagtes with this docker container.
docker-container run:
docker run -itd \
--name="mosquitto" \
--restart always \
-p 1883:1883 \
-v /home/pi/.docker/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf \
-v mosquitto_data:/mosquitto/data \
-v mosquitto_data:/mosquitto/log \
eclipse-mosquitto
my config file:
listener 1883
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
The permissions for config file (in docker container): 644 mosquitto:mosquitto
In log I see following output:
0: mosquitto version 2.0.12 starting
0: Using default config.
0: Starting in local only mode. Connections will only be possible from clients running on this machine.
0: Create a configuration file which defines a listener to allow remote access.
0: For more details see https://mosquitto.org/documentation/authentication-methods/
0: Opening ipv4 listen socket on port 1883.
0: Error: Address in use
0: Opening ipv6 listen socket on port 1883.
0: Error: Address not available
If I pub a new message I got an unknown error
# mosquitto_pub -t 'test/topic' -m 'hello, is anybody out there?'
Error: Unknown error.
It seems it doesn't load my config-file. see "0: Using default config".
Or is it something else? Maybe the permissions of the config file?
Thx
Source was that with the newer alpine image, libseccomp2 needed an update on Raspbian.
Details see here: https://github.com/eclipse/mosquitto/issues/2323#issuecomment-927367047
After that, it runs without any further problems.
Related
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?
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
I am running Mosquitto 1.4.8 on Ubuntu successfully on port 1883 (tested from another machine with mosquitto_sub/mosquitto_pub). However I am encountering issues when attempting to use another port eg.
mosquitto -p 1884 -c moddebug.conf
This works OK if I access it from the same machine e.g.:
mosquitto_pub -h 127.0.0.1 -p 1884
but if I attempt to connect from another machine I get an error:
mosquitto_pub -h IP_ADDRESS -t exmapleTopic -p 1884
Connection timed out
My moddebug.conf file is:
log_type all
log_dest file mosquitto2_log.log
The log does not provide any extra information:
Config loaded from mosdebug.conf.
Opening ipv4 listen socket on port 1884.
Opening ipv6 listen socket on port 1884.
mosquitto version 1.4.8 terminating
I have tried altering the firewall rules (but this did not help):
ufw allow 1884/tcp
Rules updated
Rules updated (v6)
This topic is about Docker networking, which I can't get to allow dockerised Jenkins to use a dockerised SMTP server.
Here's how I run my containers and connect them to a user-defined network, so that containers' name might be use as a target host:
# Run Jenkins image, with port binding, Docker sock sharing, and configuration sharing
docker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -v /root/jenkins_conf/:/var/jenkins_home/ --name jenkins jenkins/jenkins:lts
# Run SMTP image
docker run -d --name smtp namshi/smtp
# Create user-defined network
docker network create jenkins-net
# Connect both containers
docker network connect jenkins-net jenkins
docker network connect jenkins-net smtp
Within my jenkins container, I can reach the smtp service via the default 'bridge' network:
$ (echo >/dev/tcp/172.17.0.5/25) &>/dev/null && echo "open" || echo "close"
open
and I can also reach it via my user-defined network, both via IP and hostname:
$ (echo >/dev/tcp/172.18.0.3/25) &>/dev/null && echo "open" || echo "close"
open
$ (echo >/dev/tcp/smtp/25) &>/dev/null && echo "open" || echo "close"
open
So far, so good.
But then, in Jenkins > Manage Jenkins > Configure System > E-mail notification, trying to use the test email sending tool gives me following results:
SMTP server: 172.17.0.5 (SMTP container IP on the default 'bridge' network)
SMTP port: 25
=> the email is sent and duly received !
SMTP server: 172.18.0.3 (SMTP container IP on my user-defined 'jenkins-net' network)
SMTP port: 25
=> Failed to send out e-mail
com.sun.mail.smtp.SMTPAddressFailedException: 550 relay not permitted
SMTP server: smtp (SMTP container name on my user-defined 'jenkins-net' network)
SMTP port: 25
=> same error
Why the difference of behaviour from the SMTP server between the use of the 2 networks?
What am I missing about Docker networking?
Edit: So the quick solution was to run the smtp container with the --network option, instead of running it and then connecting it to the network. See Stefano's answer below for more details and adequacy.
The problem you described is unrelated to the docker networking. The namshi/smtp image uses exim4 as SMTP. In this specific exim4 setup, you're required to provide the neworks from where it's allowed to connect and send email.
Checking the entrypoint.sh file, I found the following command:
dc_relay_nets "$(ip addr show dev eth0 | awk '$1 == "inet" { print $2 }' | xargs | sed 's/ /:/g')${RELAY_NETWORKS}"
This means that by default, it'll accept the emails coming from the IP address associated with the interface eth0 and other possible RELAY_NETWORKS (if defined).
Since the container is not attached by default to the jenkins-net network at the creation, it won't recognize as valid the emails coming from that address.
Try to start the containers like this:
docker network create jenkins-net
SUBNET=$( docker network inspect \
-f '{{range .IPAM.Config}}{{.Subnet}}{{end}}' \
jenkins-net )
docker run -d \
--network jenkins-net \
-e RELAY_NETWORKS=":${SUBNET}" \
--name smtp \
namshi/smtp
docker run -d \
-p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /root/jenkins_conf/:/var/jenkins_home/ \
--network jenkins-net \
--name jenkins \
jenkins/jenkins:lts
Following the tutorial on https://docs.docker.com/get-started/part2/.
I start my docker container with docker run -p 4000:80 friendlyhello
and see
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8088/ (Press CTRL+C to quit)
But it's inaccessible from the expected path of localhost:4000.
$ curl http://localhost:4000/
curl: (7) Failed to connect to localhost port 4000: Connection refused
$ curl http://127.0.0.1:4000/
curl: (7) Failed to connect to 127.0.0.1 port 4000: Connection refused
Okay, so maybe it's not on my local host. Getting the container ID I retrieve the IP with
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7e5bace5f69c
and it returns 172.17.0.2 but no luck! curl continues to give the same responses. I can confirm something is running on 4000....
lsof -i :4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 94812 travis 18u IPv6 0x7516cbae76f408b5 0t0 TCP *:terabase (LISTEN)
I'm pulling my hair out on this. I've read through the troubleshooting guide and can confirm
* not on a proxy
* don't use a custom dns
* I'm having issues connecting to docker, not docker connecting to my pip server.
Running the app.py with python app.py the server starts and I'm able to hit it. What am I missing?
Did you accidentally put port=8088 at the bottom of your app.py file? When you are running this the last line of your output is saying that your python app is exposed on port 8088 not 80.
To confirm you can run either modify the app.py file and rebuild the image, or alternatively you could run: docker run -p 4000:8088 friendlyhello which would map your local port 4000 to 8088 in the container.
Try to run it using:
docker run -p 4000:8088 friendlyhello
As you can see from the logs, your app starts on port 8088, but you connect 4000 to 80 where on 80, nothing is actually listening.
I have installed Mosquitto on a brand new Raspberry Pi. OS is Raspbian.
I followed the instructions on the Owntracks website.
The broker is listening on port 1883 on localhost. Using a username and password I can run mosquitto_sub in one ssh session to the Pi, and receive messages sent by mosquitto_pub from another ssh session.
The broker is also listening on port 8883. I created certificates using the script in the Owntracks repository.
When I run mosquitto_pub on the Pi, using the hostname or IP-address I get an error "Error: Connection refused".
When I use localhost or 127.0.0.1 the error is "A TLS error occurred.".
If I run mosquitto_pub on my desktop computer (which is in the same LAN as the Pi), the error is "Connection refused". The command I run here is
mosquitto_pub -t owntracks/test -m Test -h pi1 --cafile ca.crt
where pi1 is the hostname of the Pi running the broker. The ca.crt file is copied from the Pi to the desktop computer.
The Mosquitto log is not showing why the connections are refused.
The TLS setup in the Mosquitto config looks like this:
listener 1883 127.0.0.1
listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate false
What is wrong in my setup?
if you try to use TLS with mosquitto
you must add this option to your command "-p 8883" to indicate the port
and you don't need to put "-h localhost or pi " because you use the client command mosquitto_pub in the same machine that run mosquitto broker
then your command we'll be :
"mosquitto_pub -d -u username -P password -t /path/to/the/topic --cafile /path/to/the/certificate -p 8883
don't forgot to comment this line
listener 1883
in your mosquitto.conf
Recreating all certificates solved the problem. Apparently I did something wrong with including local vs. remote IP-addresses and host names.
The TLS error messages are not very informative, but that probably has to do with security precautions.