Added option to change allocation range of published ports#40055
Added option to change allocation range of published ports#40055suwang48404 wants to merge 1 commit into
Conversation
Also reduce the allowed port range as the total number of containers per host is typically less than 1K. This change helps in scenarios where there are other services on the same host that uses ephemeral ports in iptables manipulation. The workflow requires changes in docker engine ( moby/moby#40055) and this change. It works as follows: 1. user can now specified to docker engine an option --published-port-range="50000-60000" as cmdline argument or in daemon.json. 2. docker engine read and pass this info to libnetwork via config.go:OptionDynamicPortRange. 3. libnetwork uses this range to allocate dynamic port henceforth. 4. --published-port-range can be set either via SIGHUP or restart docker engine 5. if --published-port-range is not set by user, a OS specific default range is used for dynamic port allocation. Linux: 49153-60999, Windows: 60000-65000 6 if --published-port-range is invalid, that is, the range given is outside of allowed default range, no change takes place. libnetwork will continue to use old/existing port range for dynamic port allocation. Signed-off-by: Su Wang <[email protected]>
|
@suwang48404 would help if you shared some examples using the |
…rts. Signed-off-by: Su Wang <[email protected]>
Also reduce the allowed port range as the total number of containers per host is typically less than 1K. This change helps in scenarios where there are other services on the same host that uses ephemeral ports in iptables manipulation. The workflow requires changes in docker engine ( moby/moby#40055) and this change. It works as follows: 1. user can now specified to docker engine an option --published-port-range="50000-60000" as cmdline argument or in daemon.json. 2. docker engine read and pass this info to libnetwork via config.go:OptionDynamicPortRange. 3. libnetwork uses this range to allocate dynamic port henceforth. 4. --published-port-range can be set either via SIGHUP or restart docker engine 5. if --published-port-range is not set by user, a OS specific default range is used for dynamic port allocation. Linux: 49153-60999, Windows: 60000-65000 6 if --published-port-range is invalid, that is, the range given is outside of allowed default range, no change takes place. libnetwork will continue to use old/existing port range for dynamic port allocation. Signed-off-by: Su Wang <[email protected]>
|
Some questions; I think SwarmKit and "regular" containers use different ranges for the ephemeral port range; IIRC, regular containers use the range that's configured on the host ( With this change;
Given that this affects both the ephemeral port range for Given a cluster with (e.g.) 3 managers and several workers; If I create a service with a port published through the ingress network;
Same, but when creating a service with
Give that this is a configuration on the daemon, we must assume that each daemon can have a different configuration, which means that if the manager picks the port, that the selected port range can be different depending on which manager I'm connected to. So, should we store this configuration in the swarm raft store instead? (similar to what we do for setting and updating this configurationPer my earlier comment; validation is done in the libnetwork code; I still have to build and test this change, but;
(Without having given this much thought, so just thinking out loud); Are there possible complications if I update this port-range? What happens to existing containers if the daemon restarts? I assume containers (and services) preserve the port, but does the daemon / swarm continue to keep track of ports that were allocated in the old range? |
|
Hi Sebastiaan, thx for review, and spending time think about it. reply inline please
===> swarm allocating range is hard coded to 30000-32767, and they are not yet tunable
=====> docker engine port allocator is used when "docker run -p ..." and "docker service create --publish mode=host", swarm port allocator is used when "docker service create --publish .."
========> each docker engine picks different port independently as port allocated by docker engine has local scope only, does not impact other node? That is, the same port allocated by docker engines can be allocated and assigned to same/different service instances on different nodes. Do we need raft in this use case?
=========> yes
Thyx, Su |
Also reduce the allowed port range as the total number of containers per host is typically less than 1K. This change helps in scenarios where there are other services on the same host that uses ephemeral ports in iptables manipulation. The workflow requires changes in docker engine ( moby#40055) and this change. It works as follows: 1. user can now specified to docker engine an option --published-port-range="50000-60000" as cmdline argument or in daemon.json. 2. docker engine read and pass this info to libnetwork via config.go:OptionDynamicPortRange. 3. libnetwork uses this range to allocate dynamic port henceforth. 4. --published-port-range can be set either via SIGHUP or restart docker engine 5. if --published-port-range is not set by user, a OS specific default range is used for dynamic port allocation. Linux: 49153-60999, Windows: 60000-65000 6 if --published-port-range is invalid, that is, the range given is outside of allowed default range, no change takes place. libnetwork will continue to use old/existing port range for dynamic port allocation. Signed-off-by: Su Wang <[email protected]>
|
For the record, the libnetwork changes needed by this PR have been introduced in moby/libnetwork#2461 and is being reverted by #43066. If someone wants to work on this PR, they'd have to re-apply the reverted commit and fix the issue described in #43054. @thaJeztah There's been no activity on this PR since two years and there's no linked issue so I'm not sure if that's really something people want. Moreover, the port range can already by configured through sysctl, so this PR only brings the config reload part. Maybe this change should be closed and mark as "won't implement" (unless there're requests for it). |
|
Agreed, IMO we should close this for now in favor of #43066. |
|
@neersighted @corhere @evol262 FYI - I recall the motivation for these changes was related to (at the time) Docker EE, to be able to reserve separate "ephemeral" port ranges for SwarmKit, "docker run", and k8s (?). Perhaps you're already carrying patches for that, but if not, perhaps this needs to be carried at some point |
published-dynamic-port-range may be specified in command line
dockerd ... -- published-dynamic-port-range="50000-60000"
or in /etc/docker/daemon.json
published-dynamic-port-range:"50000-60000" specify the range used by
docker engine to allocate published service ports.
- What I did
Added published-dynamic-port-range option to allow user to change published service port
range,
- How I did it
works in libnetwork and docker engine
- How to verify it
add/change published-dynamic-port-range is /etc/docker/daemon.json, and kill -SIGHUP DOCKERD_PID, and "docker run -p 80 SOME_WEB_SERVICE_IMG", the published port should
be allocated from new range.
- Description for the changelog
Allow user to change range of allocated published ports.
- A picture of a cute animal (not mandatory but encouraged)