I am running Eclipse MQTT server in a Docker container on Lubuntu 20.04 LTS. I want to send an MQTT message from a shell script which is executing outside the Docker container. Can anyone advise how I can do that?
This is a broad question, do you want to manually execute a command in the container’s shell?
If so, docker exec -it <container_name> [the shell command] is what you’re looking for
If you want to send MQTT messages to a container, you probably need to open the port on the container so it can receive incoming messages (doc).
Yes I want to publish an MQTT message to an MQTT server running in a Docker container on the same host.
If I run:
sudo docker exec -it mqtt-moquitto mosquitto_pub
or
sudo docker exec -it mqtt-moquitto Mosquitto_pub
I get:
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: “mosquitto_pub” executable file not found in $PATH: unknown"
(mqtt-moquitto is the name of the Eclipse Mosquitto container)
I have the default port open on the container for receiving messages.
Maybe use the official image?
docker run eclipse-mosquitto mosquitto_pub
shows the help for mosquitto_pub.
If I try that I get:
/docker-entrypoint.sh: exec: line 4: mosquitto_pub: not found
Maybe try docker pull eclipse-mosquitto first to get latest image.
That did it - many thanks!