@@ -207,14 +207,13 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
207207 if err != nil {
208208 return nil , errors .New ("invalid hostPort: " + hostPort )
209209 }
210- }
211-
212- if hostPort != "" && (endPort - startPort ) != (endHostPort - startHostPort ) {
213- // Allow host port range iff containerPort is not a range.
214- // In this case, use the host port range as the dynamic
215- // host port range to allocate into.
216- if endPort != startPort {
217- return nil , fmt .Errorf ("invalid ranges specified for container and host Ports: %s and %s" , containerPort , hostPort )
210+ if (endPort - startPort ) != (endHostPort - startHostPort ) {
211+ // Allow host port range iff containerPort is not a range.
212+ // In this case, use the host port range as the dynamic
213+ // host port range to allocate into.
214+ if endPort != startPort {
215+ return nil , fmt .Errorf ("invalid ranges specified for container and host Ports: %s and %s" , containerPort , hostPort )
216+ }
218217 }
219218 }
220219
@@ -225,11 +224,11 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
225224 containerPort = strconv .FormatUint (startPort + i , 10 )
226225 if hostPort != "" {
227226 hostPort = strconv .FormatUint (startHostPort + i , 10 )
228- }
229- // Set hostPort to a range only if there is a single container port
230- // and a dynamic host port.
231- if startPort == endPort && startHostPort != endHostPort {
232- hostPort = hostPort + "-" + strconv . FormatUint ( endHostPort , 10 )
227+ // Set hostPort to a range only if there is a single container port
228+ // and a dynamic host port.
229+ if count == 1 && startHostPort != endHostPort {
230+ hostPort += "-" + strconv . FormatUint ( endHostPort , 10 )
231+ }
233232 }
234233 ports = append (ports , PortMapping {
235234 Port : Port (containerPort + "/" + proto ),
0 commit comments