{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/12622","labels_url":"https://api.github.com/repos/docker/docker/issues/12622/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/12622/comments","events_url":"https://api.github.com/repos/docker/docker/issues/12622/events","html_url":"https://github.com/docker/docker/pull/12622","id":70028146,"number":12622,"title":"Proposal: Port Allocations from a Host Range and Host Port Persistence Policies","user":{"login":"bru7us","id":3108062,"avatar_url":"https://avatars.githubusercontent.com/u/3108062?v=3","gravatar_id":"","url":"https://api.github.com/users/bru7us","html_url":"https://github.com/bru7us","followers_url":"https://api.github.com/users/bru7us/followers","following_url":"https://api.github.com/users/bru7us/following{/other_user}","gists_url":"https://api.github.com/users/bru7us/gists{/gist_id}","starred_url":"https://api.github.com/users/bru7us/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bru7us/subscriptions","organizations_url":"https://api.github.com/users/bru7us/orgs","repos_url":"https://api.github.com/users/bru7us/repos","events_url":"https://api.github.com/users/bru7us/events{/privacy}","received_events_url":"https://api.github.com/users/bru7us/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/docker/labels/status/1-needs-design-review","name":"status/1-needs-design-review","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-04-22T05:23:20Z","updated_at":"2015-05-12T20:55:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/12622","html_url":"https://github.com/docker/docker/pull/12622","diff_url":"https://github.com/docker/docker/pull/12622.diff","patch_url":"https://github.com/docker/docker/pull/12622.patch"},"body":"Inspired by the great work of @cezarsa over in #10052, this PR adds `PortRange` to the container HostConfig and provides the `--static-port-range` command line argument for `create` and `run`.\r\n\r\nIf a range is provided, any published ports without a specified hostPort will be allocated an available host port from the provided range. Once allocated, the port is written to the HostConfig and persists as if the container had been started with `-p X:Y`.\r\n\r\nThe change allows a user/sysadmin to define a range of ports on a host exclusively for docker containers to use outside of the standard ephemeral range, but still leaves the ephemeral range available for any other true 'dynamic' allocations when they are desired."},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/101417030","html_url":"https://github.com/docker/docker/pull/12622#issuecomment-101417030","issue_url":"https://api.github.com/repos/docker/docker/issues/12622","id":101417030,"user":{"login":"bru7us","id":3108062,"avatar_url":"https://avatars.githubusercontent.com/u/3108062?v=3","gravatar_id":"","url":"https://api.github.com/users/bru7us","html_url":"https://github.com/bru7us","followers_url":"https://api.github.com/users/bru7us/followers","following_url":"https://api.github.com/users/bru7us/following{/other_user}","gists_url":"https://api.github.com/users/bru7us/gists{/gist_id}","starred_url":"https://api.github.com/users/bru7us/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bru7us/subscriptions","organizations_url":"https://api.github.com/users/bru7us/orgs","repos_url":"https://api.github.com/users/bru7us/repos","events_url":"https://api.github.com/users/bru7us/events{/privacy}","received_events_url":"https://api.github.com/users/bru7us/received_events","type":"User","site_admin":false},"created_at":"2015-05-12T20:55:46Z","updated_at":"2015-05-12T20:55:46Z","body":"> Does that stop us from being able to have a per-SPEC range, or do we just have a default bind behavior for those as well?\r\n> I'm not sure what you mean here. Could you clarify?\r\n\r\nSo the way I understand your suggestion is this: both --port-range=[range] and --persist-ports=[range] would apply to all dynamic bindings on the container (i.e. where no host port is specified). My latest implementation also provided the ability to specify a host range as `-p 8000-9000:80`, to which the containers persistence policy would also apply. This range specification is what I mean by 'per-SPEC'.\r\n\r\n> We should not allow overlapping port ranges on the command line.\r\n\r\nWhen using the argument to define behavior, that makes sense. But if I provided 2 different ranges, how do we decide which range to use for each binding where the host port is not specified?\r\n\r\nThat is, what happens to container port 90 here?:\r\n`--port-range=5000-5999 --persist-ports=6000-6100 -p 80:80 -p 90`\r\n\r\nWith my last implementation, overlaps actually don't matter because we are still using a single global port-map and a single global persistence policy. You can also use both a specified range AND the ephemeral range if you choose to do so (by specifying host port 0 for ephemeral).\r\n\r\n> No. This would the default behavior for port ranges (this is what we do with -P today and what I suggested above as --port-range).\r\n\r\nWhat we do today is equivalent to the \"static\" bind, which always allocates a new port on every start (for dynamic ports); \"soft\" tries to use the previous port if previous allocation was dynamic and only re-allocates a new one if the old is busy."}}