Explosion Pills
Explosion Pills

Reputation: 191729

Docker container with multiple configurable ports

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?

Upvotes: 3

Views: 394

Answers (1)

Ray
Ray

Reputation: 41408

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.

Upvotes: 2

Related Questions