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

DockerDockerfile

Docker Problem Overview


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

Docker Solutions


Solution 1 - Docker

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

Solution 2 - Docker

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDarVarView Question on Stackoverflow
Solution 1 - DockerDarVarView Answer on Stackoverflow
Solution 2 - DockerGh0sTView Answer on Stackoverflow