Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker expose all ports or range of ports from 7000 to 8000

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
like image 241
DarVar Avatar asked Sep 30 '22 12:09

DarVar


People also ask

Can I expose multiple ports Docker?

In your Dockerfile , you can use the verb EXPOSE to expose multiple ports.

Should I expose Docker port?

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.

What is the port range for Docker?

The default ephemeral port range from 49153 through 65535 is always used for Docker versions before 1.6.

How do I expose Docker network to port?

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.


2 Answers

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

like image 173
DarVar Avatar answered Oct 06 '22 20:10

DarVar


For anyone facing this issue and ending up on this post...the issue is still open - https://github.com/moby/moby/issues/11185

like image 7
Gh0sT Avatar answered Oct 06 '22 19:10

Gh0sT