Skip to content

Commit 03797ac

Browse files
authored
Merge pull request moby#51586 from robmry/ep_options_exposed_ports
PublishAllPorts: create port mappings for exposed ports
2 parents abd4c10 + 85b260f commit 03797ac

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

daemon/network.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,20 @@ func buildPortsRelatedCreateEndpointOptions(c *container.Container, n *libnetwor
10361036
exposedPorts []lntypes.TransportPort
10371037
publishedPorts []lntypes.PortBinding
10381038
)
1039-
for p, bindings := range c.HostConfig.PortBindings {
1039+
1040+
ports := c.HostConfig.PortBindings
1041+
if c.HostConfig.PublishAllPorts {
1042+
// Add exposed ports to a copy of the map to make sure a "publishedPorts" entry is created
1043+
// for each exposed port, even if there's no specific binding.
1044+
ports = maps.Clone(c.HostConfig.PortBindings)
1045+
for p := range c.Config.ExposedPorts {
1046+
if _, exists := ports[p]; !exists {
1047+
ports[p] = nil
1048+
}
1049+
}
1050+
}
1051+
1052+
for p, bindings := range ports {
10401053
protocol := lntypes.ParseProtocol(string(p.Proto()))
10411054
exposedPorts = append(exposedPorts, lntypes.TransportPort{
10421055
Proto: protocol,

0 commit comments

Comments
 (0)