Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to unexpose a port in Dockerfile?

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"]
like image 735
Biswas Avatar asked Nov 21 '25 18:11

Biswas


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.

docker run -d -p 10883:1883 eclipse-mosquitto

This will expose port 10883 on the host and map it to 1883 on the container.

like image 141
hardillb Avatar answered Nov 24 '25 08:11

hardillb


"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.

like image 32
Mojtaba Ahadi Avatar answered Nov 24 '25 07:11

Mojtaba Ahadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!