mirror of
https://github.com/moby/moby.git
synced 2026-06-24 08:48:23 +00:00
In rootless mode, ChildHostIP maps every IPv4 host address to 127.0.0.1 in the child network namespace. Port bindings on the same port but distinct loopback addresses (e.g. 127.0.1.2:80 and 127.0.1.3:80) were therefore both reserved as 127.0.0.1:80 by the port allocator in the child namespace, and the second binding failed with "Bind for 127.0.0.1:8080 failed: port is already allocated" even though the requested addresses do not conflict. Preserve IPv4 loopback host addresses as the child host IP instead. The child namespace's lo interface covers all of 127.0.0.0/8, so the addresses are bindable as-is, and RootlessKit's builtin port driver both listens on the requested parent address and dials the requested child address verbatim. Port drivers that disallow loopback child IPs (slirp4netns) are unaffected: their forced non-loopback childIP is selected before the loopback fallback. Signed-off-by: Andrew Liu <andrewjliu22@gmail.com>