There are two things you need to consider from the Mosquitto side when running on Docker. First off, you need to configure one or more ports that Mosquitto will listen on. You do this in your configuration file. Here are some examples, there are more details on the configuration file at mosquitto.conf man page | Eclipse Mosquitto and
# Listener with no encryption and no authentication/access control
listener 1883
allow_anonymous true
# Listener with no encryption, with password and acl file access
# See https://mosquitto.org/man/mosquitto_passwd-1.html for info on password files
listener 1883
password_file /mosquitto/config/mosquitto.passwd
acl_file /mosquitto/config/mosquitto.acl
# Listener with no encryption, with dynamic security plugin
listener 1883
plugin /usr/lib/mosquitto_dynamic_security.so
plugin_opt_config_file /mosquitto/data/mosquitto-dynsec.json
# Listener with encryption, with dynamic security plugin
# See https://mosquitto.org/documentation/dynamic-security/
listener 8883
certfile /mosquitto/data/server.crt
keyfile /mosquitto/data/server.key
plugin /usr/lib/mosquitto_dynamic_security.so
plugin_opt_config_file /mosquitto/data/mosquitto-dynsec.json
Once you have your configuration file, it needs to be provided to your container. I would suggest using a local directory structure like this for your container data:
The second step is that you need to provide access to the port used in the container. If you’re running docker directly it would look like this, assuming you’re using one of the port 1883 options and following the above local directory structure:
docker run -it -v mosquitto/config:/mosquitto/config -v mosquitto/data:/mosquitto/data -p 1883:1883 eclipse-mosquitto:2
That gives you a running Mosquitto instance listening on port 1883/8883 of the NAS external interface. The next step is to find the external IP address of your NAS and connect to it - doing that is down to you.
Yes I have a fixed IP address for my NAS which is an internal address, I have an external address for my internet connection but I’m not sure what I use as an address when trying to access the NAS externally ie to access the Mosquitto broker which is running in Docker - where do I find the address that will get me through to the broker ?
in this case you have to set something in your router up that your internal device gets linked to an externally reachable IP and port. If your external IP is dynamic then you can look at https://www.noip.com/free, this is a free service to link a URL from them to your dynamic IP. I haven’t tried it out yet, but @Tizian recently forwarded me that interesting tutorial where somebody makes a raspberry pi externally available: HOW TO CONNECT A RASPBERRY PI WEB SERVER TO THE INTERNET: Host a website | Raspberry Pi Projects - YouTube
Again disclaimer: I did not try it yet and all stuff where you make an IP/port externally available you have to be careful that you do not create an IT sec vulnerability.
Good luck Let us know if you got it running finally and how you did it …