Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation for mapping a range of host-ports to a single container-port fails #1074

Closed
thaJeztah opened this issue May 22, 2018 · 0 comments · Fixed by #1102
Closed

Validation for mapping a range of host-ports to a single container-port fails #1074

thaJeztah opened this issue May 22, 2018 · 0 comments · Fixed by #1102

Comments

@thaJeztah
Copy link
Member

When running containers, it is both possible to publish a range of host/container ports using the shorthand startport-endport notation:

docker container run -d -p 8080-8081:80-81 --name multi nginx:alpine
fd9b13ed2a03270445812d9349831f936edc55342a9cc7209fc2ab57b0f37974

It's also possible to map multiple host-ports to a single container port:

docker container run -d -p 8080-8081:80 --name multi nginx:alpine
8e289ce242e51934156cd6a2cf088bbf7d3ae645a42208feb5447fbb77526e0f

Mapping a range of host ports to a range of container ports works for services:

docker service create --name multi -p 8080-8081:80-81 nginx:alpine

9q6g4m30qqh5vw4ruffgn16px
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

However, trying to map a range of hosts-ports to a single container port fails in validation:

docker service create --name multi -p 8080-8081:80 nginx:alpine

invalid argument "8080-8090:80" for "-p, --publish" flag: invalid hostport binding (8080-8090) for port (80)
See 'docker service create --help'.

The last example should work

Error looks to be generated in this function;

cli/opts/port.go

Lines 143 to 167 in 99bd7ed

// ConvertPortToPortConfig converts ports to the swarm type
func ConvertPortToPortConfig(
port nat.Port,
portBindings map[nat.Port][]nat.PortBinding,
) ([]swarm.PortConfig, error) {
ports := []swarm.PortConfig{}
for _, binding := range portBindings[port] {
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)
}
hostPort, err := strconv.ParseUint(binding.HostPort, 10, 16)
if err != nil && binding.HostPort != "" {
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%s)", binding.HostPort, port.Port())
}
ports = append(ports, swarm.PortConfig{
//TODO Name: ?
Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
TargetPort: uint32(port.Int()),
PublishedPort: uint32(hostPort),
PublishMode: swarm.PortConfigPublishModeIngress,
})
}
return ports, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants