3

I have a container that runs a node app with three servers: one server for public data and two webpack servers. By default these run on ports 3000, 3001, and 3002, but these ports can all be configured.

It seems that I would be able to run the container like so:

docker run -p 3000:3003 -p 3001:3004 -p 3002:3005 -e 'APP_PORT=3003' \
  -e 'NG_PORT=3004' -e 'RC_PORT=3005' --expose 3003 --expose 3004 --expose 3005 \
  ajcrites/webf

However there are two problems with this approach:

  1. There is a tremendous amount of redundancy
  2. I want the default ports to be used/exposed if nothing is specified

Is there a simpler way to expose all of the configurable ports whether or not they are changed from the defaults?

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • I post this comment just in case. It may not be what you're searching for (I'm not sure I understand well what you're searching for, if that's not relevant I apologize), but there is the **-P** option that automatically assigns external ports to exposed ports. Plus you can expose ports by adding an **EXPOSE** directive to a dockerfile. – vmonteco Mar 04 '16 at 22:00
  • yoiu don't need to repeat the `-p`, you can specify several different port (without them being contiguous) – Auzias Mar 05 '16 at 08:28

1 Answers1

2

You wouldn't want to expose ALL ports, however you can expose and bind by range since at least docker 1.5:

docker run -p 3000-3002:3003-3005

I don't think you need to use --expose when you publish.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
Ray
  • 40,256
  • 21
  • 101
  • 138
  • Don't you still need to do `--expose` with the same port numbers as well? – Explosion Pills Mar 04 '16 at 19:56
  • You can expose a range too. – Ray Mar 04 '16 at 19:59
  • @ExplosionPills Expose only exposes ports to other running services in the running docker container, but not outside, so you could always expose a wide range if you don't need to lock down by port inside docker: http://stackoverflow.com/questions/22111060/difference-between-expose-and-publish-in-docker – Ray Mar 04 '16 at 20:04
  • @ExplosionPills If you publish you're not having to explicilty expose. Expose is needed if you don't publish to make them available inter-service. – Ray Mar 04 '16 at 20:06
  • `-p 3000-3002:3003-3005` does this automatically map the ports one-to-one? – Explosion Pills Mar 04 '16 at 20:06
  • @ExplosionPills yep, I believe so. – Ray Mar 04 '16 at 20:08