I am trying to deploy a mosquitto MQTT broker in our corporate cloud through docker image. The allowed ports that are exposed are in the range of 10000-10999.
By default eclipse-mosquitto image exposes port 1883. Is there a way to unexpose port 1883 and expose 10883?
This is my Dockerfile:
FROM eclipse-mosquitto:latest
COPY mosquitto.conf /mosquitto/config/
COPY docker-entrypoint.sh mosquitto-no-auth.conf /
EXPOSE 10883
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]
2
Answers
Just because the container exposes port 1883 that doesn’t mean that’s the port you need to use access a running instance.
When you start the container using the
docker run
command you get to decide what port on the host machine is mapped to that port on the container.E.g.
This will expose port 10883 on the host and map it to 1883 on the container.
"Expose" in dockerfile is kind of a meta data which tells which port you should work with. It does not open any port. So you can easily open any port you want.