|  | @@ -1,9 +1,9 @@
 | 
	
		
			
				|  |  |  package run
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import (
 | 
	
		
			
				|  |  | -	"fmt"
 | 
	
		
			
				|  |  |  	"strconv"
 | 
	
		
			
				|  |  | -	"strings"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	"github.com/docker/go-connections/nat"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	"github.com/docker/api/containers"
 | 
	
		
			
				|  |  |  )
 | 
	
	
		
			
				|  | @@ -14,27 +14,34 @@ type runOpts struct {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func toPorts(ports []string) ([]containers.Port, error) {
 | 
	
		
			
				|  |  | +	_, bindings, err := nat.ParsePortSpecs(ports)
 | 
	
		
			
				|  |  | +	if err != nil {
 | 
	
		
			
				|  |  | +		return nil, err
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  	var result []containers.Port
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	for _, port := range ports {
 | 
	
		
			
				|  |  | -		parts := strings.Split(port, ":")
 | 
	
		
			
				|  |  | -		if len(parts) != 2 {
 | 
	
		
			
				|  |  | -			return nil, fmt.Errorf("unable to parse ports %q", port)
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		source, err := strconv.Atoi(parts[0])
 | 
	
		
			
				|  |  | -		if err != nil {
 | 
	
		
			
				|  |  | -			return nil, err
 | 
	
		
			
				|  |  | +	for port, bind := range bindings {
 | 
	
		
			
				|  |  | +		for _, portbind := range bind {
 | 
	
		
			
				|  |  | +			var hostPort uint32
 | 
	
		
			
				|  |  | +			if portbind.HostPort != "" {
 | 
	
		
			
				|  |  | +				hp, err := strconv.Atoi(portbind.HostPort)
 | 
	
		
			
				|  |  | +				if err != nil {
 | 
	
		
			
				|  |  | +					return nil, err
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				hostPort = uint32(hp)
 | 
	
		
			
				|  |  | +			} else {
 | 
	
		
			
				|  |  | +				hostPort = uint32(port.Int())
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +			result = append(result, containers.Port{
 | 
	
		
			
				|  |  | +				HostPort:      hostPort,
 | 
	
		
			
				|  |  | +				ContainerPort: uint32(port.Int()),
 | 
	
		
			
				|  |  | +				Protocol:      port.Proto(),
 | 
	
		
			
				|  |  | +				HostIP:        portbind.HostIP,
 | 
	
		
			
				|  |  | +			})
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		destination, err := strconv.Atoi(parts[1])
 | 
	
		
			
				|  |  | -		if err != nil {
 | 
	
		
			
				|  |  | -			return nil, err
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		result = append(result, containers.Port{
 | 
	
		
			
				|  |  | -			Source:      uint32(source),
 | 
	
		
			
				|  |  | -			Destination: uint32(destination),
 | 
	
		
			
				|  |  | -		})
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	return result, nil
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |