Skip to content

Commit

Permalink
daemon: release sandbox even when NetworkDisabled
Browse files Browse the repository at this point in the history
When the default bridge is disabled by setting dockerd's `--bridge=none`
option, the daemon still creates a sandbox for containers with no
network attachment specified. In that case `NetworkDisabled` will be set
to true.

However, currently the `releaseNetwork` call will early return if
NetworkDisabled is true. Thus, these sandboxes won't be deleted until
the daemon is restarted. If a high number of such containers are
created, the daemon would then take few minutes to start.

See moby#42461.

Signed-off-by: payall4u <payall4u@qq.com>
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
  • Loading branch information
payall4u authored and akerouanton committed Oct 16, 2023
1 parent adea457 commit 9664f33
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion daemon/container_operations.go
Expand Up @@ -967,10 +967,17 @@ func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerID st

func (daemon *Daemon) releaseNetwork(container *container.Container) {
start := time.Now()
// If live-restore is enabled, the daemon cleans up dead containers when it starts up. In that case, the
// netController hasn't been initialized yet and so we can't proceed.
// TODO(aker): If we hit this case, the endpoint state won't be cleaned up (ie. no call to cleanOperationalData).
if daemon.netController == nil {
return
}
if container.HostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled {
// If the container uses the network namespace of another container, it doesn't own it -- nothing to do here.
if container.HostConfig.NetworkMode.IsContainer() {
return
}
if container.NetworkSettings == nil {
return
}

Expand Down

0 comments on commit 9664f33

Please sign in to comment.