Proposal: Change --publish=SPEC to allow binding to custom host port ranges#12927
Proposal: Change --publish=SPEC to allow binding to custom host port ranges#12927thaJeztah merged 1 commit intomoby:masterfrom lindenlab:custom-host-port-ranges
Conversation
|
It looks like there are a few conflicts between this and #12622, I think the better solution would be some combination of both PRs (see: #10052 (comment)) - I just never got around to implementing this format. A couple of questions for you:
I love what you've done with the port range keys in the global map. I started out doing something similar, but with multiple port maps so I came across an issue where you can have potentially overlapping maps that will conflict with each other. This is a much more elegant approach. |
|
Here is an example session: The restart does not attempt to keep the same port, but it does re-allocate from within the same requested port range. |
|
Thanks for the follow up - I'm struggling to understand the benefit of using this instead of just any ephemeral port (outside of the scope of the other PRs). If every restart auto-allocates a port - why not just use the ephemeral range? I think my latest comment (#12622 (comment)) sums up the ultimate solution (a combination of your work, mine and that in #10052), do you have any feedback on that? |
|
My use-case is that I'm attempting to use AWS Security Groups to differentiate between 'public' vs 'private' port ranges to allow external traffic. I need to be able to assign container ports in a more controlled manner than just using ephemeral ports. I'll take a look at #12622 and provide some feedback |
|
@docker/core-maintainers for design review. I think it is smaller and less-breaking than #12622 |
|
Rebased off master. Updated vendor/src/github.com/docker/libnetwork to match moby/libnetwork#285 |
|
@dkjer have a comment / question for your PR in libnetwork moby/libnetwork#285. Can you please address that so that we can get this PR moving ? |
|
@mavenugo Sure, apologies for the delay |
See moby/moby#12927 for docker portion. Signed-off-by: Don Kjer <don.kjer@gmail.com>
Notable changes include : - moby#285 : Fix required for moby#12927 - moby#283 : Code re-architecture/tech-debt in bridge driver - Upgraded to latest Netlink library - Fixed certain race-conditions Signed-off-by: Madhu Venugopal <madhu@docker.com>
|
@dkjer latest libnetwork with your patch is in docker master now. Can you please rebase to the latest and update this PR ? |
|
@mavenugo Rebased |
pkg/nat/nat.go
Outdated
There was a problem hiding this comment.
|
@mavenugo, did you see moby/libnetwork#453 yet? If we can catch it before this PR gets merged we can easily maintain full backward compatibility in libnetwork with a minor update to this PR to include separate start port and specified port. If this gets merged first, there will be a dependency on docker and libnetwork to be updated together to get persistence policies in. |
|
@mavenugo Error string updated / commit squashed |
pkg/nat/nat.go
Outdated
There was a problem hiding this comment.
Is there a reason why we are trying to ignore the error (other than reason mentioned here?).
I guess we could break this assumption with a simple Unit-Test.
Though it is not something we will see today, this assumption can lead to issues down the line.
Hence it would be better to not ignore the error.
There was a problem hiding this comment.
@mavenugo I agree. This was just following the pattern given in Port.Int(), which ignores errors with the same assumption. I will add the error case
|
@dkjer Could you please cover this in current integration cli test for port specs: |
Signed-off-by: Don Kjer <don.kjer@gmail.com> Changing vendor/src/github.com/docker/libnetwork to match lindenlab/libnetwork custom-host-port-ranges-1.7 branch
|
LGTM |
|
@bru7us sorry not yet. we have start with design review of moby/libnetwork#453 and make sure the features align with all the upcoming features. We have to also look @ all the design review comments of #12622. I think it is okay to keep 2 separate. |
|
Ok, thanks for the response. |
|
@dkjer Thanks for addressing the comments. But, I think we need some inputs from the docs team especially because the ping @moxiegirl @thaJeztah |
There was a problem hiding this comment.
@dkjer Thank you for your contribution. This is great information and I think expanding it will help readers get this information more easily. Also, I'd like it if we could put this information in a table. The table is beyond your scope, if you are willing to add it, good. If not I can carry the work for you.
--> https://gist.github.com/moxiegirl/8fa6820db70a011a8414
| Option | Description |
|---|---|
--expose=[] |
Expose a port or a range of ports from the container,without publishing it to your host |
-P=false |
Publish all exposed ports to the host interfaces. |
-p=[] |
Publish a container᾿s port or a range of ports to the host. The value's format can be any of:
Use the
You can specify both the
You can also specify a range for |
--link="" |
Add link to another container (id:alias, name:alias, name, id) |
There was a problem hiding this comment.
@moxiegirl I won't have time for a couple days to update this; if you could carry the doc changes that would be excellent
There was a problem hiding this comment.
@dkjer shall I suggest a minor tweak to this Doc and get it merged ?
@moxiegirl can update the doc in a later commit with the table structure that she proposed ?
The proposed documentation is confusing
When specifying a range for hostPort only, the containerPort must not be a range.
Confusing and it is conflicting with the other option of providing both hostPort range and containerPort range.
In this case the container port is published somewhere within the specified hostPort range.
I would reword it as `In this case the container port is mapped to a host port somewhere within the specified hostPort range``
There was a problem hiding this comment.
@mavenugo I'll pick up your change wording when I carry the docs.
|
@mavenugo I'll LGTM and carry the change after the merge if you are cool with it. |
|
sgtm, agreed to update after merging so LGTM @moxiegirl I'll merge this one, then I'll rebase #15675 when I'm home, does that work for you? |
Proposal: Change --publish=SPEC to allow binding to custom host port ranges
|
@moxiegirl Thanks for carrying the doc changes! |
|
Thank you @dkjer for contributing, and being so patient! |
This PR is similar to #12622, but is more narrow and focuses purely on the publish SPEC. This change would allow specifying a range for the hostPort of a publish SPEC (iff containerPort is not a range), which would override the default binding to ephemeral ports and instead bind within the specified hostPort range:
Example:
This would bind port 5000 in the container to a randomly available port between 8000 and 9000 on the host.