daemon: Daemon.buildSandboxOptions: use range when looping

Makes the code slightly more readable.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-24 11:58:10 +02:00
parent 33b4285eb1
commit 2b028dc55b
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -121,26 +121,25 @@ func (daemon *Daemon) buildSandboxOptions(cfg *config.Config, container *contain
Port: portNum,
})
binding := bindings[port]
for i := 0; i < len(binding); i++ {
newP, err := nat.NewPort(nat.SplitProtoPort(binding[i].HostPort))
for _, binding := range bindings[port] {
newP, err := nat.NewPort(nat.SplitProtoPort(binding.HostPort))
var portStart, portEnd int
if err == nil {
portStart, portEnd, err = newP.Range()
}
if err != nil {
return nil, fmt.Errorf("Error parsing HostPort value(%s):%v", binding[i].HostPort, err)
return nil, fmt.Errorf("Error parsing HostPort value(%s):%v", binding.HostPort, err)
}
publishedPorts = append(publishedPorts, types.PortBinding{
Proto: portProto,
Port: portNum,
HostIP: net.ParseIP(binding[i].HostIP),
HostIP: net.ParseIP(binding.HostIP),
HostPort: uint16(portStart),
HostPortEnd: uint16(portEnd),
})
}
if container.HostConfig.PublishAllPorts && len(binding) == 0 {
if container.HostConfig.PublishAllPorts && len(bindings[port]) == 0 {
publishedPorts = append(publishedPorts, types.PortBinding{
Proto: portProto,
Port: portNum,