29

How to expose port ranges (like "3000-4000:3000-4000") in docker-compose.yml file

ports: - "3000-4000:3000-4000"

it not working. Please help me to resolve it

Murali Manchadikkal
  • 887
  • 1
  • 10
  • 7
  • Possible duplicate of [Docker expose all ports or range of ports from 7000 to 8000](https://stackoverflow.com/questions/28717464/docker-expose-all-ports-or-range-of-ports-from-7000-to-8000) – Rumid Aug 08 '17 at 06:32
  • How is it "not working". Please provide the error you are getting. – Ayushya Aug 09 '17 at 03:18
  • in docker-compose syntax is different than command line, user is trying to find that, It is not duplicate because that threat is about command line – nerkn Mar 10 '21 at 05:09
  • This question related to port publishing, not exposing ports at all. The top answer also relates to port publishing, not port exposing. These are well defined terms in docker and are being misused here. If the question is about publishing please rephrase. – Laurence Fass Apr 21 '23 at 15:31

1 Answers1

50

There is possibly mistake in the syntax you are using. The ports are defined in the next line and after leaving some space. It should work and as specified in the reference. See example below:

ports:
 - "3000"
 - "3000-3005"
 - "8000:8000"
 - "9090-9091:8080-8081"
 - "49100:22"
 - "127.0.0.1:8001:8001"
 - "127.0.0.1:5000-5010:5000-5010"
 - "6060:6060/udp"
Ayushya
  • 9,599
  • 6
  • 41
  • 57