Docker container with multiple networks binds to one IP only
Problem
I have got in to the issue when I have added VerneMQ broker to the existing network an also to another docker network. Old network is with currently working containers and is created using some python script. New Docker network is built with docker-compose and has few other containers, I wanted to make VerneMQ from new network to communicate with old one so attached old network to new docker-compose. Other containers from docker-compose does not need to access old network so that is easy done. But now I have got in to problems when port 1883 is listening only to one IP address that is found using vernemq.sh script. Also I can not override using Docker environment variables as lines are included in the script after environment variables are parsed.
Expected behavior
I think in Docker container listeners should be listening to all interfaces as users control what can access service inside the Docker container by attaching to the one or more networks, for example I can add third docker network that is responsible for monitoring but do not want to allow it to my other containers.
So current listeners that are set in the script vernemq.sh
echo "listener.tcp.default = ${IP_ADDRESS}:1883" >> /vernemq/etc/vernemq.conf
echo "listener.ws.default = ${IP_ADDRESS}:8080" >> /vernemq/etc/vernemq.conf
echo "listener.vmq.clustering = ${IP_ADDRESS}:44053" >> /vernemq/etc/vernemq.conf
echo "listener.http.metrics = ${IP_ADDRESS}:8888" >> /vernemq/etc/vernemq.conf
${IP_ADDRESS} should be replaced by 0.0.0.0. If we have only one network it will work as before and listen to one IP and localhost.
Also these code lines should be placed right after the '########## Start ##########' line so they could be overridden by parsing environment variables.
I do not know how clustering will work in this case but If I understand correctly it should be working fine.
It looks like these issues are similar: #110 and #107
I understand that we can mount whole configuration vernemq.conf.local but in most cases there is enough to use ENV variables so I do not have to play with config file and mount it directly.
thanks for reporting. 0.0.0.0 will work for MQTT and HTTP , but NOT for the clustering listener.
In most cases Docker container will have only one network so one IP and setting MQTT, HTTP and WS listeners to 0.0.0.0 will solve problems when somebody will use multiple networks to access broker.
Regarding clustering no problem to stick to one IP.
So if somebody can update script and update docker image it would be perfect.
I got the same issue when tried to build cluster with 3 servers , and have 3 containers are in those 3 servers
For other people looking for the exact solution:
I noticed that setting the default listeners via the environment variable (e.g. DOCKER_VERNEMQ_LISTENER__TCP__DEFAULT) is being overridden by the initialisation script bin/vernemq.sh and will not work.
Looking at the script and after testing setting the following environment variable works:
DOCKER_IP_ADDRESS=0.0.0.0