@@ -204,14 +204,13 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
204204 if err != nil {
205205 return nil , errors .New ("invalid hostPort: " + hostPort )
206206 }
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+ }
215214 }
216215 }
217216
@@ -223,11 +222,11 @@ func ParsePortSpec(rawPort string) ([]PortMapping, error) {
223222 hPort := ""
224223 if hostPort != "" {
225224 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+ }
231230 }
232231 ports = append (ports , PortMapping {
233232 Port : cPort ,
0 commit comments