Can I specify a port range in a Dockerfile
EXPOSE 7000-8000
and when running the container bind all these exposed ports to the same ports on the host machine?
docker run -p 7000-8000:7000-8000
In your Dockerfile , you can use the verb EXPOSE to expose multiple ports.
Some standard ports are 80 for webservers, 443 for webservers running over encryption (TLS/SSL), and 25 for mail. So when you want to allow applications to connect to your container, you need to expose one or more ports to the outside world.
The default ephemeral port range from 49153 through 65535 is always used for Docker versions before 1.6.
You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls ). You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag.
Since Docker 1.5 you can now expose a range of ports to other linked containers using:
The Dockerfile EXPOSE command:
EXPOSE 7000-8000
or The Docker run command:
docker run --expose=7000-8000
Or instead you can publish a range of ports to the host machine via Docker run command:
docker run -p 7000-8000:7000-8000
For anyone facing this issue and ending up on this post...the issue is still open - https://github.com/moby/moby/issues/11185
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