Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Expose a range of ports

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 
like image 883
Sohail Avatar asked Jan 19 '15 10:01

Sohail


People also ask

Can Docker expose multiple ports?

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.

How do I expose Docker container ports?

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.

What is the port range for Docker?

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.

What is difference between expose and publishing?

Short answer: EXPOSE is a way of documenting. --publish (or -p ) is a way of mapping a host port to a running container port.


1 Answers

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.

like image 100
Umair A. Shahid Avatar answered Sep 20 '22 13:09

Umair A. Shahid