Home > Enterprise >  Is there a way to unexpose a port in Dockerfile?
Is there a way to unexpose a port in Dockerfile?

Time:03-30

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

CodePudding user response:

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.

CodePudding user response:

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

  • Related