mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
PublishAllPorts: create port mappings for exposed ports
Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
@@ -1036,7 +1036,20 @@ func buildPortsRelatedCreateEndpointOptions(c *container.Container, n *libnetwor
|
|||||||
exposedPorts []lntypes.TransportPort
|
exposedPorts []lntypes.TransportPort
|
||||||
publishedPorts []lntypes.PortBinding
|
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()))
|
protocol := lntypes.ParseProtocol(string(p.Proto()))
|
||||||
exposedPorts = append(exposedPorts, lntypes.TransportPort{
|
exposedPorts = append(exposedPorts, lntypes.TransportPort{
|
||||||
Proto: protocol,
|
Proto: protocol,
|
||||||
|
|||||||
Reference in New Issue
Block a user