mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Prior to commit fe856b9, containers' network sandbox and interfaces were
created before the containerd task. Now, it's created after.
If this step fails, the containerd task is forcefully deleted, and an
event is sent to the c8d event monitor, which triggers `handleContainerExit`.
Then this method tries to restart the faulty container.
This leads to containers with a published port already in use to be
stuck in a tight restart loop (if they're started with
`--restart=always`) until the port is available. This is needlessly
spamming the daemon logs.
Prior to that commit, a published port already in use wouldn't trigger
the restart process.
This commit adds a check to `handleContainerExit` to ignore exit events
if the latest container error is related to networking setup.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package daemon // import "github.com/docker/docker/daemon"
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/container"
|
|
"github.com/docker/docker/daemon/config"
|
|
"github.com/docker/docker/errdefs"
|
|
"github.com/docker/docker/libcontainerd/types"
|
|
"github.com/docker/docker/oci"
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
|
|
// initializeCreatedTask performs any initialization that needs to be done to
|
|
// prepare a freshly-created task to be started.
|
|
func (daemon *Daemon) initializeCreatedTask(
|
|
ctx context.Context,
|
|
cfg *config.Config,
|
|
tsk types.Task,
|
|
ctr *container.Container,
|
|
spec *specs.Spec,
|
|
) error {
|
|
if ctr.Config.NetworkDisabled {
|
|
return nil
|
|
}
|
|
nspath, ok := oci.NamespacePath(spec, specs.NetworkNamespace)
|
|
if ok && nspath == "" { // the runtime has been instructed to create a new network namespace for tsk.
|
|
sb, err := daemon.netController.GetSandbox(ctr.ID)
|
|
if err != nil {
|
|
return errdefs.System(err)
|
|
}
|
|
if err := sb.SetKey(ctx, fmt.Sprintf("/proc/%d/ns/net", tsk.Pid())); err != nil {
|
|
return errdefs.System(err)
|
|
}
|
|
}
|
|
if err := daemon.allocateNetwork(ctx, cfg, ctr); err != nil {
|
|
return fmt.Errorf("%s: %w", errSetupNetworking, err)
|
|
}
|
|
return nil
|
|
}
|