When the container stops or during `restore`, `daemon.releaseNetwork` is
used to clear all net-related state carried by a container. However, the
fields `SandboxID` and `SandboxKey` are never cleared. On the next start,
these fields will be replaced with new values. There's no point in
preserving these data since they became invalid as soon as the container
stopped.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -1019,6 +1019,9 @@ func (daemon *Daemon) releaseNetwork(ctx context.Context, container *container.C |
| 1019 | 1019 |
return |
| 1020 | 1020 |
} |
| 1021 | 1021 |
|
| 1022 |
+ container.NetworkSettings.SandboxID = "" |
|
| 1023 |
+ container.NetworkSettings.SandboxKey = "" |
|
| 1024 |
+ |
|
| 1022 | 1025 |
var networks []*libnetwork.Network |
| 1023 | 1026 |
for n, epSettings := range container.NetworkSettings.Networks {
|
| 1024 | 1027 |
if nw, err := daemon.FindNetwork(getNetworkID(n, epSettings.EndpointSettings)); err == nil {
|
| ... | ... |
@@ -85,6 +85,8 @@ func TestNetworkStateCleanupOnDaemonStart(t *testing.T) {
|
| 85 | 85 |
|
| 86 | 86 |
inspect, err := apiClient.ContainerInspect(ctx, cid) |
| 87 | 87 |
assert.NilError(t, err) |
| 88 |
+ assert.Assert(t, inspect.NetworkSettings.SandboxID != "") |
|
| 89 |
+ assert.Assert(t, inspect.NetworkSettings.SandboxKey != "") |
|
| 88 | 90 |
assert.Assert(t, inspect.NetworkSettings.Ports["80/tcp"] != nil) |
| 89 | 91 |
|
| 90 | 92 |
assert.NilError(t, d.Kill()) |
| ... | ... |
@@ -92,5 +94,7 @@ func TestNetworkStateCleanupOnDaemonStart(t *testing.T) {
|
| 92 | 92 |
|
| 93 | 93 |
inspect, err = apiClient.ContainerInspect(ctx, cid) |
| 94 | 94 |
assert.NilError(t, err) |
| 95 |
+ assert.Assert(t, inspect.NetworkSettings.SandboxID == "") |
|
| 96 |
+ assert.Assert(t, inspect.NetworkSettings.SandboxKey == "") |
|
| 95 | 97 |
assert.Assert(t, inspect.NetworkSettings.Ports["80/tcp"] == nil) |
| 96 | 98 |
} |