0
votes

eclipse-mosquitto installed them with Docker on Ubuntu. I want to execute the "docker exec" commands but it gives the following error? Can you help?

sudo docker ps

outPut:

CONTAINER ID: b416d716ffd6   IMAGE: eclipse-mosquitto     COMMAND: "/docker-entrypoint.…"   CREATED: 2 days ago   STATUS: Up 44 minutes   PORTS: 0.0.0.0:9001->9001/tcp, 0.0.0.0:11883->1883/tcp   NAME: charming_bohr

command:

sudo docker exec -it b416d716ffd6 /bin/bash

OutPut: OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown


for: The total number of bytes received since the broker started.

sudo docker exec -it b416d716ffd6 $SYS/broker/bytes/received

OutPut:

OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "/broker/bytes/received": stat /broker/bytes/received: no such file or directory: unknown
1
Hello, for the first error it means that it can't find /bin/bash in the container, it's probably not installed. You could try using sh instead -> sudo docker exec -it b416d716ffd6 shPaul

1 Answers

0
votes

There are two distinct problem.

  1. eclipse mosquitto image does not include bash so you need to use a different shell, for instance sh

    `sudo docker exec -it b416d716ffd6 /bin/sh

  2. $SYS/broker/bytes/received is a special topic managed automatically and internally by mosquitto, you can access it "from outside" without exec-ing anything into the running container, for instance you can use mosquitto sub (sudo apt-get install -y mosquitto_clients, if you do not already have it)

    mosquitto_sub -t '$SYS/broker/bytes/received'

adding -h option if mosquitto is not on localhost, -p if it is not on the default port, -d if you want it more verbose and so on.

For reference, this need of an MQTT client is clearly explained in mosquitto man page:

Broker Status Clients can find information about the broker by subscribing to topics in the $SYS hierarchy as follows. Topics marked as static are only sent once per client on subscription. All other topics are updated every sys_interval seconds. If sys_interval is 0, then updates are not sent.

Note that if you are using a command line client to interact with the $SYS topics and your shell interprets $ as an environment variable, you need to place the topic in single quotes '$SYS/...' or to escape the dollar symbol: $SYS/... otherwise the $SYS will be treated as an environment variable.

$SYS/broker/bytes/received The total number of bytes received since the broker started.