mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
libcontainerd: create unstarted tasks
Split task creation and start into two separate method calls in the libcontainerd API. Clients now have the opportunity to inspect the freshly-created task and customize its runtime environment before starting execution of the user-specified binary. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/docker/docker/api/types/events"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/compatcontext"
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -198,16 +199,32 @@ func (daemon *Daemon) containerStart(ctx context.Context, daemonCfg *configStore
|
||||
if err != nil {
|
||||
return setExitCodeFromError(container.SetExitCode, err)
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := ctr.Delete(compatcontext.WithoutCancel(ctx)); err != nil {
|
||||
log.G(ctx).WithError(err).WithField("container", container.ID).
|
||||
Error("failed to delete failed start container")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// TODO(mlaventure): we need to specify checkpoint options here
|
||||
tsk, err := ctr.Start(context.TODO(), // Passing ctx to ctr.Start caused integration tests to be stuck in the cleanup phase
|
||||
tsk, err := ctr.NewTask(context.TODO(), // Passing ctx caused integration tests to be stuck in the cleanup phase
|
||||
checkpointDir, container.StreamConfig.Stdin() != nil || container.Config.Tty,
|
||||
container.InitializeStdio)
|
||||
if err != nil {
|
||||
if err := ctr.Delete(context.Background()); err != nil {
|
||||
log.G(ctx).WithError(err).WithField("container", container.ID).
|
||||
Error("failed to delete failed start container")
|
||||
return setExitCodeFromError(container.SetExitCode, err)
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := tsk.ForceDelete(compatcontext.WithoutCancel(ctx)); err != nil {
|
||||
log.G(ctx).WithError(err).WithField("container", container.ID).
|
||||
Error("failed to delete task after fail start")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err := tsk.Start(context.TODO()); err != nil { // passing ctx caused integration tests to be stuck in the cleanup phase
|
||||
return setExitCodeFromError(container.SetExitCode, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user