mirror of https://github.com/docker/docs.git
Fix port mapping unit tests
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
167403988d
commit
1d4de9ce1f
|
@ -1188,10 +1188,18 @@ func (container *Container) allocateNetwork() error {
|
||||||
portJob.Setenv("Proto", port.Proto())
|
portJob.Setenv("Proto", port.Proto())
|
||||||
portJob.Setenv("ContainerPort", port.Port())
|
portJob.Setenv("ContainerPort", port.Port())
|
||||||
|
|
||||||
|
portEnv, err := portJob.Stdout.AddEnv()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := portJob.Run(); err != nil {
|
if err := portJob.Run(); err != nil {
|
||||||
eng.Job("release_interface", container.ID).Run()
|
eng.Job("release_interface", container.ID).Run()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
b.HostIp = portEnv.Get("HostIP")
|
||||||
|
b.HostPort = portEnv.Get("HostPort")
|
||||||
|
|
||||||
|
binding[i] = b
|
||||||
}
|
}
|
||||||
bindings[port] = binding
|
bindings[port] = binding
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,10 @@ var (
|
||||||
"192.168.44.1/24",
|
"192.168.44.1/24",
|
||||||
}
|
}
|
||||||
|
|
||||||
bridgeIface string
|
bridgeIface string
|
||||||
defaultBindingIP net.IP
|
bridgeNetwork *net.IPNet
|
||||||
bridgeNetwork *net.IPNet
|
|
||||||
|
|
||||||
|
defaultBindingIP = net.ParseIP("0.0.0.0")
|
||||||
currentInterfaces = make(map[string]*networkInterface)
|
currentInterfaces = make(map[string]*networkInterface)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,7 +72,9 @@ func InitDriver(job *engine.Job) engine.Status {
|
||||||
bridgeIP = job.Getenv("BridgeIP")
|
bridgeIP = job.Getenv("BridgeIP")
|
||||||
)
|
)
|
||||||
|
|
||||||
defaultBindingIP = net.ParseIP(job.Getenv("DefaultBindingIP"))
|
if defaultIP := job.Getenv("DefaultBindingIP"); defaultIP != "" {
|
||||||
|
defaultBindingIP = net.ParseIP(defaultIP)
|
||||||
|
}
|
||||||
|
|
||||||
bridgeIface = job.Getenv("BridgeIface")
|
bridgeIface = job.Getenv("BridgeIface")
|
||||||
if bridgeIface == "" {
|
if bridgeIface == "" {
|
||||||
|
@ -382,6 +384,8 @@ func Release(job *engine.Job) engine.Status {
|
||||||
// Allocate an external port and map it to the interface
|
// Allocate an external port and map it to the interface
|
||||||
func AllocatePort(job *engine.Job) engine.Status {
|
func AllocatePort(job *engine.Job) engine.Status {
|
||||||
var (
|
var (
|
||||||
|
err error
|
||||||
|
|
||||||
ip = defaultBindingIP
|
ip = defaultBindingIP
|
||||||
id = job.Args[0]
|
id = job.Args[0]
|
||||||
hostIP = job.Getenv("HostIP")
|
hostIP = job.Getenv("HostIP")
|
||||||
|
@ -396,7 +400,7 @@ func AllocatePort(job *engine.Job) engine.Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
// host ip, proto, and host port
|
// host ip, proto, and host port
|
||||||
hostPort, err := portallocator.RequestPort(ip, proto, hostPort)
|
hostPort, err = portallocator.RequestPort(ip, proto, hostPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Error(err)
|
job.Error(err)
|
||||||
return engine.StatusErr
|
return engine.StatusErr
|
||||||
|
@ -423,6 +427,14 @@ func AllocatePort(job *engine.Job) engine.Status {
|
||||||
}
|
}
|
||||||
network.PortMappings = append(network.PortMappings, host)
|
network.PortMappings = append(network.PortMappings, host)
|
||||||
|
|
||||||
|
out := engine.Env{}
|
||||||
|
out.Set("HostIP", ip.String())
|
||||||
|
out.SetInt("HostPort", hostPort)
|
||||||
|
|
||||||
|
if _, err := out.WriteTo(job.Stdout); err != nil {
|
||||||
|
job.Error(err)
|
||||||
|
return engine.StatusErr
|
||||||
|
}
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func RequestPort(ip net.IP, proto string, port int) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user requested a specific port to be allocated
|
// If the user requested a specific port to be allocated
|
||||||
if port != 0 {
|
if port > 0 {
|
||||||
if err := registerSetPort(ip, proto, port); err != nil {
|
if err := registerSetPort(ip, proto, port); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue