diff --git a/opts/port.go b/opts/port.go index 020a5d1e1c..531908fb24 100644 --- a/opts/port.go +++ b/opts/port.go @@ -98,7 +98,11 @@ func (p *PortOpt) Set(value string) error { ports, portBindings, _ := nat.ParsePortSpecs([]string{value}) for port := range ports { - portConfigs = append(portConfigs, ConvertPortToPortConfig(port, portBindings)...) + portConfig, err := ConvertPortToPortConfig(port, portBindings) + if err != nil { + return err + } + portConfigs = append(portConfigs, portConfig...) } p.ports = append(p.ports, portConfigs...) } @@ -129,11 +133,14 @@ func (p *PortOpt) Value() []swarm.PortConfig { func ConvertPortToPortConfig( port nat.Port, portBindings map[nat.Port][]nat.PortBinding, -) []swarm.PortConfig { +) ([]swarm.PortConfig, error) { ports := []swarm.PortConfig{} for _, binding := range portBindings[port] { - hostPort, _ := strconv.ParseUint(binding.HostPort, 10, 16) + 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())), @@ -142,5 +149,5 @@ func ConvertPortToPortConfig( PublishMode: swarm.PortConfigPublishModeIngress, }) } - return ports + return ports, nil }