PublishAllPorts: create port mappings for exposed ports

Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
Rob Murray
2025-11-24 20:26:30 +00:00
parent 6e52828ec3
commit 85b260fba8

View File

@@ -1036,7 +1036,20 @@ func buildPortsRelatedCreateEndpointOptions(c *container.Container, n *libnetwor
exposedPorts []lntypes.TransportPort
publishedPorts []lntypes.PortBinding
)
for p, bindings := range c.HostConfig.PortBindings {
ports := c.HostConfig.PortBindings
if c.HostConfig.PublishAllPorts {
// Add exposed ports to a copy of the map to make sure a "publishedPorts" entry is created
// for each exposed port, even if there's no specific binding.
ports = maps.Clone(c.HostConfig.PortBindings)
for p := range c.Config.ExposedPorts {
if _, exists := ports[p]; !exists {
ports[p] = nil
}
}
}
for p, bindings := range ports {
protocol := lntypes.ParseProtocol(string(p.Proto()))
exposedPorts = append(exposedPorts, lntypes.TransportPort{
Proto: protocol,