13

I'm am deploying an app inside a docker container that randomly assigns ports when it starts. The problem is I want to use docker-compose but is there a way to expose all ports for the service using docker-compose? Without docker-compose, I would use docker run ... -P

Thanks

Philip K. Adetiloye
  • 3,102
  • 4
  • 37
  • 63
  • Possible duplicate of [Docker: Expose a range of ports](http://stackoverflow.com/questions/28022656/docker-expose-a-range-of-ports) – mttdbrd Nov 12 '16 at 17:28
  • @mttdbrd - nope, read the question! – Philip K. Adetiloye Nov 12 '16 at 21:53
  • Sorry. What version of Docker Compose are you using? This was supposed to be fixed in 1.6.0: https://github.com/docker/compose/pull/2629. You would basically use a range in a string: - "8200-8219" – mttdbrd Nov 12 '16 at 23:23
  • I do not thing that you would be able to expose ALL ports (1-65535). That would left no ports for host. Probably you need some ports for SSH, docker demon, etc. – Bartosz Bilicki Dec 18 '16 at 10:37

2 Answers2

18

I'd recommend using port ranges i.e

ports: - "1-65535:1-65535"

You will probably need to tinker with this range according to your app specifications so that you won't accidentally expose something that's already in use by the host (such as SSH).

amirb
  • 387
  • 3
  • 8
1

docker-compose version 1.25.0


Use it like following


ports: [22, 23]

It needs to be array of port numbers.

Kumar
  • 41
  • 5