-
Notifications
You must be signed in to change notification settings - Fork 5.7k
add port range support to docker compose #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,7 +102,7 @@ An entry with the ip address and hostname will be created in `/etc/hosts` inside | |
| ### ports | ||
|
|
||
| Expose ports. Either specify both ports (`HOST:CONTAINER`), or just the container | ||
| port (a random host port will be chosen). | ||
| port (a random host port will be chosen). You can specify a port range instead of a single port (`START-END`). If you use a range for the container ports, you may specify a range for the host ports as well. both ranges must be of equal size. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @moxiegirl My take: this seems to suggest on first reading that you can specify a range of container ports but a single host port, which I don't think is correct. Perhaps: Expose ports. You can specify just a container port (which will be mapped to a random host port), or both ( You can optionally pass in ranges of port numbers. If you're specifying host ports as well as container ports, the host and container port ranges must be the same size. |
||
|
|
||
| > **Note:** When mapping ports in the `HOST:CONTAINER` format, you may experience | ||
| > erroneous results when using a container port lower than 60, because YAML will | ||
|
|
@@ -111,9 +111,12 @@ port (a random host port will be chosen). | |
|
|
||
| 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" | ||
|
|
||
| ### expose | ||
|
|
||
|
|
@@ -371,3 +374,4 @@ Each of these is a single value, analogous to its | |
| - [Command line reference](cli.md) | ||
| - [Compose environment variables](env.md) | ||
| - [Compose command line completion](completion.md) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ simple: | |
| ports: | ||
| - '3000' | ||
| - '49152:3001' | ||
| - '49153-49154:3002-3003' | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uvgroovy thanks for the contribution. We just sorted this same material out on a docker/docker pr. So, let's try it here:
---> https://gist.github.com/moxiegirl/3dded271198e4107c4d2
ports
Makes an exposed port accessible on a host and the port is available to
any client that can reach that host. Docker binds the exposed port to a random
port on the host within an ephemeral port range defined by
/proc/sys/net/ipv4/ip_local_port_range. You can also map to a specific port or range of ports.Acceptable formats for a
portsvalue are:containerPortip:hostPort:containerPortip::containerPorthostPort:containerPortYou can specify a range for both the
hostPortand thecontainerPortvalues.When specifying ranges, the container port values in the range must match the
number of host port values in the range, for example,
1234-1236:1234-1236/tcp. Once a host is running, use the 'docker-compose port' commandto see the actual mapping.
The following configuration shows examples of the port formats in use:
When mapping ports using the
hostPort:containerPortformat, you mayexperience erroneous results when specifying a container port lower than 60. This
happens because YAML parses numbers in the format
xx:yyas sexagesimal (base60). To avoid this problem, always explicitly specify your port
mappings as strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. The only thing I'd change is this line:
This should instead read
docker-compose port.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aanand updated comment and the gist.