From cc18a9c650305a377150c67e5ed10f1e2f19b685 Mon Sep 17 00:00:00 2001 From: pysqz Date: Wed, 28 Aug 2013 03:14:21 +0800 Subject: [PATCH] Also reuse forwarding ports --- container.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/container.go b/container.go index 0fae60402c..ae96504a9f 100644 --- a/container.go +++ b/container.go @@ -801,10 +801,22 @@ func (container *Container) allocateNetwork() error { } } + var portSpecs []string + if !container.State.Ghost { + portSpecs = container.Config.PortSpecs + } else { + for backend, frontend := range container.NetworkSettings.PortMapping["Tcp"] { + portSpecs = append(portSpecs, fmt.Sprintf("%s:%s/tcp",frontend, backend)) + } + for backend, frontend := range container.NetworkSettings.PortMapping["Udp"] { + portSpecs = append(portSpecs, fmt.Sprintf("%s:%s/udp",frontend, backend)) + } + } + container.NetworkSettings.PortMapping = make(map[string]PortMapping) container.NetworkSettings.PortMapping["Tcp"] = make(PortMapping) container.NetworkSettings.PortMapping["Udp"] = make(PortMapping) - for _, spec := range container.Config.PortSpecs { + for _, spec := range portSpecs { nat, err := iface.AllocatePort(spec) if err != nil { iface.Release()