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