mirror of https://github.com/docker/cli.git
Fix mapping a range of host ports to a single container port
Signed-off-by: Sami Tabet <salph.tabet@gmail.com>
This commit is contained in:
parent
31d99ba630
commit
63e5c29e00
21
opts/port.go
21
opts/port.go
|
@ -151,17 +151,22 @@ func ConvertPortToPortConfig(
|
||||||
if binding.HostIP != "" && binding.HostIP != "0.0.0.0" {
|
if binding.HostIP != "" && binding.HostIP != "0.0.0.0" {
|
||||||
logrus.Warnf("ignoring IP-address (%s:%s:%s) service will listen on '0.0.0.0'", binding.HostIP, binding.HostPort, port)
|
logrus.Warnf("ignoring IP-address (%s:%s:%s) service will listen on '0.0.0.0'", binding.HostIP, binding.HostPort, port)
|
||||||
}
|
}
|
||||||
hostPort, err := strconv.ParseUint(binding.HostPort, 10, 16)
|
|
||||||
|
startHostPort, endHostPort, err := nat.ParsePortRange(binding.HostPort)
|
||||||
|
|
||||||
if err != nil && binding.HostPort != "" {
|
if err != nil && binding.HostPort != "" {
|
||||||
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%s)", binding.HostPort, port.Port())
|
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%s)", binding.HostPort, port.Port())
|
||||||
}
|
}
|
||||||
ports = append(ports, swarm.PortConfig{
|
|
||||||
//TODO Name: ?
|
for i := startHostPort; i <= endHostPort; i++ {
|
||||||
Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
|
ports = append(ports, swarm.PortConfig{
|
||||||
TargetPort: uint32(port.Int()),
|
//TODO Name: ?
|
||||||
PublishedPort: uint32(hostPort),
|
Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
|
||||||
PublishMode: swarm.PortConfigPublishModeIngress,
|
TargetPort: uint32(port.Int()),
|
||||||
})
|
PublishedPort: uint32(i),
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ports, nil
|
return ports, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,40 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: "80-82:8080/udp",
|
||||||
|
expected: []swarm.PortConfig{
|
||||||
|
{
|
||||||
|
Protocol: "udp",
|
||||||
|
TargetPort: 8080,
|
||||||
|
PublishedPort: 80,
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Protocol: "udp",
|
||||||
|
TargetPort: 8080,
|
||||||
|
PublishedPort: 81,
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Protocol: "udp",
|
||||||
|
TargetPort: 8080,
|
||||||
|
PublishedPort: 82,
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "80-80:8080/tcp",
|
||||||
|
expected: []swarm.PortConfig{
|
||||||
|
{
|
||||||
|
Protocol: "tcp",
|
||||||
|
TargetPort: 8080,
|
||||||
|
PublishedPort: 80,
|
||||||
|
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var port PortOpt
|
var port PortOpt
|
||||||
|
|
Loading…
Reference in New Issue