Is it possible to expose a range of ports while starting Docker container?
a command like so would be very helpful:
docker run -p 127.0.0.1:8000-9000:8000-9000
Exposing multiple ports in the same service Your service exposes only a single port, but services can also support multiple ports. For example, if your pods listened on two ports—let's say 8080 for HTTP and 8443 for HTTPS—you could use a single service to forward both port 80 and 443 to the pod's ports 8080 and 8443.
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.
The default reserved ports are 22 for SSH, the Docker ports 2375 and 2376, and the Amazon ECS container agent ports 51678-51680. Any host port that was previously specified in a running task is also reserved while the task is running. That is, after a task stops, the host port is released.
Short answer: EXPOSE is a way of documenting. --publish (or -p ) is a way of mapping a host port to a running container port.
Here is a similar question that caters your requirement as well. Docker expose all ports or range of ports from 7000 to 8000
To summarize here, Yes it is possible since Docker version 1.5. You can expose port range when executing docker run
command like this:
docker run -p 192.168.0.10:8000-9000:8000-9000
or
docker run -p 8000-9000:8000-9000
I have verified that its working fine on my machine using Docker version 1.6.
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