Stable IPs causes some regressions in the way people use Docker, see GH#8493.
Reverting it for 1.3, we'll enable it back for the next release.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
| ... | ... |
@@ -564,6 +564,8 @@ func (container *Container) RestoreNetwork() error {
|
| 564 | 564 |
// cleanup releases any network resources allocated to the container along with any rules |
| 565 | 565 |
// around how containers are linked together. It also unmounts the container's root filesystem. |
| 566 | 566 |
func (container *Container) cleanup() {
|
| 567 |
+ container.ReleaseNetwork() |
|
| 568 |
+ |
|
| 567 | 569 |
// Disable all active links |
| 568 | 570 |
if container.activeLinks != nil {
|
| 569 | 571 |
for _, link := range container.activeLinks {
|
| ... | ... |
@@ -1019,14 +1021,8 @@ func (container *Container) initializeNetworking() error {
|
| 1019 | 1019 |
container.Config.NetworkDisabled = true |
| 1020 | 1020 |
return container.buildHostnameAndHostsFiles("127.0.1.1")
|
| 1021 | 1021 |
} |
| 1022 |
- // Backward compatibility: |
|
| 1023 |
- // Network allocation used to be done when containers started, not when they |
|
| 1024 |
- // were created, therefore we might be starting a legacy container that |
|
| 1025 |
- // doesn't have networking. |
|
| 1026 |
- if !container.isNetworkAllocated() {
|
|
| 1027 |
- if err := container.AllocateNetwork(); err != nil {
|
|
| 1028 |
- return err |
|
| 1029 |
- } |
|
| 1022 |
+ if err := container.AllocateNetwork(); err != nil {
|
|
| 1023 |
+ return err |
|
| 1030 | 1024 |
} |
| 1031 | 1025 |
return container.buildHostnameAndHostsFiles(container.NetworkSettings.IPAddress) |
| 1032 | 1026 |
} |
| ... | ... |
@@ -93,10 +93,6 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos |
| 93 | 93 |
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
| 94 | 94 |
return nil, nil, err |
| 95 | 95 |
} |
| 96 |
- // We may only allocate the network if a host config was passed, otherwise we'll miss port mappings. |
|
| 97 |
- if err := container.AllocateNetwork(); err != nil {
|
|
| 98 |
- return nil, nil, err |
|
| 99 |
- } |
|
| 100 | 96 |
} |
| 101 | 97 |
if err := container.ToDisk(); err != nil {
|
| 102 | 98 |
return nil, nil, err |
| ... | ... |
@@ -370,16 +370,6 @@ func (daemon *Daemon) restore() error {
|
| 370 | 370 |
registeredContainers = append(registeredContainers, container) |
| 371 | 371 |
} |
| 372 | 372 |
|
| 373 |
- // Restore networking of registered containers. |
|
| 374 |
- // This must be performed prior to any IP allocation, otherwise we might |
|
| 375 |
- // end up giving away an already allocated address. |
|
| 376 |
- for _, container := range registeredContainers {
|
|
| 377 |
- if err := container.RestoreNetwork(); err != nil {
|
|
| 378 |
- log.Errorf("Failed to restore network for %v: %v", container.Name, err)
|
|
| 379 |
- continue |
|
| 380 |
- } |
|
| 381 |
- } |
|
| 382 |
- |
|
| 383 | 373 |
// check the restart policy on the containers and restart any container with |
| 384 | 374 |
// the restart policy of "always" |
| 385 | 375 |
if daemon.config.AutoRestart {
|
| ... | ... |
@@ -94,8 +94,6 @@ func (daemon *Daemon) Destroy(container *Container) error {
|
| 94 | 94 |
return err |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 |
- container.ReleaseNetwork() |
|
| 98 |
- |
|
| 99 | 97 |
// Deregister the container before removing its directory, to avoid race conditions |
| 100 | 98 |
daemon.idIndex.Delete(container.ID) |
| 101 | 99 |
daemon.containers.Delete(container.ID) |
| ... | ... |
@@ -1937,100 +1937,6 @@ func TestRunMutableNetworkFiles(t *testing.T) {
|
| 1937 | 1937 |
} |
| 1938 | 1938 |
} |
| 1939 | 1939 |
|
| 1940 |
-func TestRunStableIPAndPort(t *testing.T) {
|
|
| 1941 |
- const nContainers = 2 |
|
| 1942 |
- var ids, ips, macs, ports [nContainers]string |
|
| 1943 |
- |
|
| 1944 |
- // Setup: Create a couple of containers and collect their IPs and public ports. |
|
| 1945 |
- for i := 0; i < nContainers; i++ {
|
|
| 1946 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "1234", "busybox", "top") |
|
| 1947 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 1948 |
- if err != nil {
|
|
| 1949 |
- t.Fatal(err) |
|
| 1950 |
- } |
|
| 1951 |
- ids[i] = strings.TrimSpace(out) |
|
| 1952 |
- |
|
| 1953 |
- ips[i], err = inspectField(ids[i], "NetworkSettings.IPAddress") |
|
| 1954 |
- errorOut(err, t, out) |
|
| 1955 |
- if ips[i] == "" {
|
|
| 1956 |
- t.Fatal("IP allocation failed")
|
|
| 1957 |
- } |
|
| 1958 |
- |
|
| 1959 |
- macs[i], err = inspectField(ids[i], "NetworkSettings.MacAddress") |
|
| 1960 |
- errorOut(err, t, out) |
|
| 1961 |
- |
|
| 1962 |
- portCmd := exec.Command(dockerBinary, "port", ids[i], "1234") |
|
| 1963 |
- ports[i], _, err = runCommandWithOutput(portCmd) |
|
| 1964 |
- errorOut(err, t, out) |
|
| 1965 |
- if ports[i] == "" {
|
|
| 1966 |
- t.Fatal("Port allocation failed")
|
|
| 1967 |
- } |
|
| 1968 |
- } |
|
| 1969 |
- |
|
| 1970 |
- // Stop them all. |
|
| 1971 |
- for _, id := range ids {
|
|
| 1972 |
- cmd := exec.Command(dockerBinary, "stop", id) |
|
| 1973 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 1974 |
- if err != nil {
|
|
| 1975 |
- t.Fatal(err, out) |
|
| 1976 |
- } |
|
| 1977 |
- } |
|
| 1978 |
- |
|
| 1979 |
- // Create a new container and ensure it's not getting the IP or port of some stopped container. |
|
| 1980 |
- {
|
|
| 1981 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "1234", "busybox", "top") |
|
| 1982 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 1983 |
- errorOut(err, t, out) |
|
| 1984 |
- |
|
| 1985 |
- id := strings.TrimSpace(out) |
|
| 1986 |
- ip, err := inspectField(id, "NetworkSettings.IPAddress") |
|
| 1987 |
- errorOut(err, t, out) |
|
| 1988 |
- |
|
| 1989 |
- portCmd := exec.Command(dockerBinary, "port", id, "1234") |
|
| 1990 |
- port, _, err := runCommandWithOutput(portCmd) |
|
| 1991 |
- errorOut(err, t, out) |
|
| 1992 |
- |
|
| 1993 |
- for i := range ids {
|
|
| 1994 |
- if ip == ips[i] {
|
|
| 1995 |
- t.Fatalf("Conflicting IP: %s", ip)
|
|
| 1996 |
- } |
|
| 1997 |
- if port == ports[i] {
|
|
| 1998 |
- t.Fatalf("Conflicting port: %s", port)
|
|
| 1999 |
- } |
|
| 2000 |
- } |
|
| 2001 |
- } |
|
| 2002 |
- |
|
| 2003 |
- // Start the containers back, and ensure they are getting the same IPs, MACs and ports. |
|
| 2004 |
- for i, id := range ids {
|
|
| 2005 |
- runCmd := exec.Command(dockerBinary, "start", id) |
|
| 2006 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 2007 |
- errorOut(err, t, out) |
|
| 2008 |
- |
|
| 2009 |
- ip, err := inspectField(id, "NetworkSettings.IPAddress") |
|
| 2010 |
- errorOut(err, t, out) |
|
| 2011 |
- |
|
| 2012 |
- mac, err := inspectField(id, "NetworkSettings.MacAddress") |
|
| 2013 |
- errorOut(err, t, out) |
|
| 2014 |
- |
|
| 2015 |
- portCmd := exec.Command(dockerBinary, "port", ids[i], "1234") |
|
| 2016 |
- port, _, err := runCommandWithOutput(portCmd) |
|
| 2017 |
- errorOut(err, t, out) |
|
| 2018 |
- |
|
| 2019 |
- if ips[i] != ip {
|
|
| 2020 |
- t.Fatalf("Container started with a different IP: %s != %s", ip, ips[i])
|
|
| 2021 |
- } |
|
| 2022 |
- if macs[i] != mac {
|
|
| 2023 |
- t.Fatalf("Container started with a different MAC: %s != %s", mac, macs[i])
|
|
| 2024 |
- } |
|
| 2025 |
- if ports[i] != port {
|
|
| 2026 |
- t.Fatalf("Container started with a different port: %s != %s", port, ports[i])
|
|
| 2027 |
- } |
|
| 2028 |
- } |
|
| 2029 |
- |
|
| 2030 |
- deleteAllContainers() |
|
| 2031 |
- logDone("run - ips and ports must not change")
|
|
| 2032 |
-} |
|
| 2033 |
- |
|
| 2034 | 1940 |
// Ensure that CIDFile gets deleted if it's empty |
| 2035 | 1941 |
// Perform this test by making `docker run` fail |
| 2036 | 1942 |
func TestRunCidFileCleanupIfEmpty(t *testing.T) {
|
| ... | ... |
@@ -2139,7 +2045,7 @@ func TestRunPortInUse(t *testing.T) {
|
| 2139 | 2139 |
t.Fatal(err) |
| 2140 | 2140 |
} |
| 2141 | 2141 |
defer l.Close() |
| 2142 |
- cmd := exec.Command(dockerBinary, "run", "-p", port+":80", "busybox", "true") |
|
| 2142 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "-p", port+":80", "busybox", "top") |
|
| 2143 | 2143 |
out, _, err := runCommandWithOutput(cmd) |
| 2144 | 2144 |
if err == nil {
|
| 2145 | 2145 |
t.Fatalf("Binding on used port must fail")
|
| ... | ... |
@@ -2157,7 +2063,7 @@ func TestRunPortProxy(t *testing.T) {
|
| 2157 | 2157 |
defer deleteAllContainers() |
| 2158 | 2158 |
|
| 2159 | 2159 |
port := "12345" |
| 2160 |
- cmd := exec.Command(dockerBinary, "run", "-p", port+":80", "busybox", "true") |
|
| 2160 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "-p", port+":80", "busybox", "top") |
|
| 2161 | 2161 |
|
| 2162 | 2162 |
out, _, err := runCommandWithOutput(cmd) |
| 2163 | 2163 |
if err != nil {
|