mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51586 from robmry/ep_options_exposed_ports
PublishAllPorts: create port mappings for exposed ports
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user