7

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 
Sohail
  • 4,506
  • 2
  • 38
  • 42
  • possible duplicated question http://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container – bachr Jan 19 '15 at 10:43
  • 1
    No it wasn't a duplicated of the mentioned question. There is a newer question very similar that has already been resolved. In case anybody lands here, see: http://stackoverflow.com/questions/28717464/docker-expose-all-ports-or-range-of-ports-from-7000-to-8000 – Gonfva Mar 18 '15 at 19:41

1 Answers1

9

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.

Community
  • 1
  • 1
Umair A. Shahid
  • 134
  • 1
  • 4
  • Just one caveat, if you try to expose more than 1000 ports one some systems it will be blocked. The work-around is to use ``--net host`` which exposes docker to the host network port controller. – Oliver Dixon Aug 16 '22 at 16:54