In your Dockerfile , you can use the verb EXPOSE to expose multiple ports.
There are several ways to do this: you can expose a port via the --expose flag at runtime, or include an EXPOSE instruction in the Dockerfile. You can also publish ports by using the -p or -P flags in the Docker run string. There's also container linking via --link .
Need of exposing ports. In order to make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, we can use the -P or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.
When running using --network host
there is no need to map the ports. All the docker container ports will be available since the network host mode makes the container use the host's network stack.
Also the EXPOSE 8080 61616 5672 61613 5445 1883
is not needed. This instruction doesn't do anything. It is just a way to document which ports need to be mapped.
In short, running docker run --network host ...
will expose all the container ports.
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
More information on the Docker documentation portal.
Using host
networking will expose almost all the ports just like you're running the application in the host machine. If port flags are used when running in host networking mode, those flags are ignored with a warning
Note: Given that the container does not have its own IP-address when using host mode networking, port-mapping does not take effect, and the -p, --publish, -P, and --publish-all option are ignored, producing a warning instead:
WARNING: Published ports are discarded when using host network mode
Make sure your host is a Linux host because host networking is only supported by Linux hosts.
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
This is mentioned in Docker documentation it self. View particular Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With