Docker Community Forums

Share and learn in the Docker community.

Zigbee2mqtt not reachable over published port

I am running zigbee2mqtt in a container, just like mosquitto. According to the logging, there is a connection established between both containers over port 1883.
Although I am not able to reach the website of the zigbeemqtt container.
In the configuration it mentions port 8081, although when checking for open ports inside the container (using this command: sudo netstat -tulpn | grep :8081), its doesn’t pop up. So I suppose this port is not published.

How can I fix this issue and publish the site of the zigbee2mqtt container ?

Please share how you started your containers.
If you show us what you did, we can see what might cause the issue without having to guess and assume everything you may have or may not have done.

Below the commands I used to deploy the containers.

Mosquitto

docker run -itd --name=mqtt --restart=always --net=bridge -v /mosquitto/config:/mosquitto/config -v /mosquitto/data:/mosquitto/data -v /mosquitto/log:/mosquitto/log eclipse-mosquitto

Zigbee2mqtt
https://www.zigbee2mqtt.io/guide/installation/02_docker.html#updating

wget https://raw.githubusercontent.com/Koenkk/zigbee2mqtt/master/data/configuration.yaml -P data
docker run --device=/dev/ttyACM0 -v $(pwd)/data:/app/data -v /run/udev:/run/udev :ro -e TZ=Europe/Amsterdam koenkk/zigbee2mqtt

I re-formated your post. Please use the </> icon next time when you post commands or code snippets, as it is easier to read.

Both containers run in the bridge network. You configured mosquito to specifcly use the bridge network, while Zigbee2mqtt implicitly uses the same network, as it’s the default when no network is configured.

You need to think about the context you are running something. Thus localhost of a container is neither the same localhost as it is for the host, nor for another container.

You will want to create a user defined networkdocker network create mynetwork as it will provide dns-based service discovery - it will allow you to use the container name (–name containername) to communicate with another container in the same network. Then use docker run --network mynetwork... to run your containers.

Though, have you considered to use docker-compose? It will make your life easier!

Oh, I forget to mention that your docker run commands have no publised ports at all. You need to add -p ${hostport}:${containerport} somewhere between docker run and the image.

Of couse you need to replace the variable ${hostport} with the host port you want to publish the container port to and replace ${containerport} with the container port the application is listing on inside the container (please use the exact ports as refered in the images description here).

Thanks for the information. I’ll give it another try tomorrow. over the last 10 days, I am trying to get it working for at least 3 hours every day. I wonder if it’s going to work somewhere in the future.

If you once understand “the docker way”, it becomes less complicated.

But I must admit the Zigbee2mqtt description is kind of irritating, as their first command line example is incomplete - it doesn’t mention the publised ports at all. Though, you can spot them immediatly in the docker-compose.yml declaration they have underneath.

Thanks again. really appreciated.
It’s getting clearer for me every day, although still a lot to learn.
I use to delete everything now and do a new deployment.

The configuration for mosquitto I have now is as followed:

mosquitto.conf:
persistence true
allow_anonymous true
connection_messages true
listener 1883
listener 9001

#locations
persistence_location /docker/mosquitto/data
log_dest file /docker/mosquitto/log/mosquitto.log

docker deployment:

docker run -itd --name=mqtt -p 1883:1883 -p 9001:9001 --restart=always --net=mynetwork -v /docker/mosquitto/config:/mosquitto/config -v /docker/mosquitto/data:/mosquitto/data -v /docker/mosquitto/log:/mosquitto/log eclipse-mosquitto

It is now properly mapping the ports, deployed to own created network and redirects certain folders. a few questions.

Question 1 is most important to me, cause I need to know if the container works fine and that I can proceed with the deployment of zigbee2mqtt

  1. can I connect to the mosquitto website that is published ?
    if so, how can I reach it ?
    I try to access the website through the host ip address of the pi (port 1883 or 9001), that doesn’t work. The created network (mynetwork) has it’s own subnet, but I cannot reach that ip address from my client.

  2. the docker deploymentscript above redirects certain folders, but it doesn’t create a log file on the redirected location, how do I verify the redirect works ?

This should have worked. You access the service inside the container by using the host name or ip and the published host port. This should work if the service is realy listening on the container port you used for the mapping. If it doesn’t it is either the wrong container port - or an error prevents the service from actualy running. You should see eveindence for that in the container logs (docker logs mqtt) .

I am not entirely realy sure what you mean. But is still try to give it a shot: If you bind a host folder into a container folder, no redirect takes place, the host folder is simply mount additionaly into the specified container folder. The process inside the container of course must use the container folder!

I noticed that I am able to setup a connection to a port on the container, see the log below. I uses MQTT Explorer using the host IP and the port 1883. so connectivity seems to be there.

I looked in to the logs, thanks for the tip, and I see that there are a few issues.
Especially regarding the redirects. You can see the docker run command I published in my earlier message, which should redirect the moquitto folder and the sub folders below. they should be pointing to the /docker/mosquitto/ (log, data, config) in the config folder I created the mosquitto.conf file, but I think the container is looking at another path.

How do I get to know where it is looking at ?

Error: Unable to open config file /mosquitto/config/mosquitto.conf
Error: No such file or directory.
Config loaded from /mosquitto/config/mosquitto.conf
New connection from 192.168.178.101:63042 on port 1883
Client <unknown> disconnected due to malformed packet
Error: Unable to open log file /docker/mosquitto/log/mosquitto.log for writing


May I ask you to re-read the second part of my last reponse and put it into your own words what you understood? Please ask, if you don’t understand something in the response, before you introducing new/different information. It will be less frustrating for both sides :slight_smile:

There is no such thing as a redirect of folders!

If you have host folder /a and bind it into container folder /b (using -v /a:/b), whatever you put on the host in /a, will be seen in the container /b and the other way arround. The left hand side before the colon is always the host side, the right hand side after the colon is always the container side. Please always use the container side as written in the image description, as the applicaion usualy is prepared to work with those pre-defined folder - unless you know exectly why you are doing it differently and how to configure the application inside the container to work with the modified location.

May I suggest this fabulous docker training: Introduction to Containers. It should give you a proper foundation to undestand how docker works and how it needs to be used.

To match the right hand side of your volume mappings, this must be::

mosquitto.conf:
persistence true
allow_anonymous true
connection_messages true
listener 1883
listener 9001 

#locations
persistence_location /mosquitto/data
log_dest file /mosquitto/log/mosquitto.log

You have to use the container paths, not the host paths, as the continer is an isolated environment and knows nothing about the ressources of your host. Is it realy valid that you declare two listeners in the conf file?

Thanks for all the information. I’ll be following the training as advised, very usefull.
I am confident that the current configuration of mosquitto and zigbee2mqtt is now fine.
checked all logs and there are no issues. zigbee2mqtt is also able to connect to mqtt, which is also nice.

One thing I wonder, I cannot access the websites of zigbee2mqtt and mosquitto… although they are exposed on port 1883/8081, entering the host ip address using this port doesn’t present a website. The following message retuns when trying to acces the sites:
ERR_CONNECTION_REFUSED

Are you sure that both even provide a webapp/dashboard? Does the documentation mention a webapp / dashboard feature or is it just your expectation that they should have a webapp/dashboard?

I wouldn’t be surprised if both only provide apis and backend services. It is not untypical for message brokers to be shipped without an UI. But typicaly can be found as third party solution.

Update: zigbee2mqtt mentions a build-in frontend, but you need to fix your port mappping from -p 8081:8081 to -p 8081:8080, as the frontend listens on port 8080 inside the image.

For mosquito you will have to use a third party product like https://mqttfx.jensd.de , http://www.eclipse.org/paho/components/mqtt-spy, or whatever you find. On Chrome you can use the extensions Websocket Client or MQTTLens

You might be right about that, I think the only container with a frontend is the zigbee2mqtt container. I adjusted the port mapping as suggested. so all seems to be ok. Although still no frontend. I need to dive into the container configuation. thanks for the support!

By the way, if anyone has a suggestion on how to be able to get the frontend working, please let me know. my browser keeps coming with the following message: ERR_CONNECTION_REFUSED