[ctr] add --detach to run
This allows the user to detach from the container after it has started. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
2e004086cf
commit
c7dc795455
@ -96,6 +96,10 @@ var runCommand = cli.Command{
|
|||||||
Name: "null-io",
|
Name: "null-io",
|
||||||
Usage: "send all IO to /dev/null",
|
Usage: "send all IO to /dev/null",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "detach,d",
|
||||||
|
Usage: "detach from the task after it has started execution",
|
||||||
|
},
|
||||||
}, snapshotterFlags...),
|
}, snapshotterFlags...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -105,6 +109,7 @@ var runCommand = cli.Command{
|
|||||||
id = context.Args().Get(1)
|
id = context.Args().Get(1)
|
||||||
imageRef = context.Args().First()
|
imageRef = context.Args().First()
|
||||||
tty = context.Bool("tty")
|
tty = context.Bool("tty")
|
||||||
|
detach = context.Bool("detach")
|
||||||
)
|
)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -122,20 +127,20 @@ var runCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if context.Bool("rm") {
|
if context.Bool("rm") && !detach {
|
||||||
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
||||||
}
|
}
|
||||||
task, err := newTask(ctx, container, context.String("checkpoint"), tty, context.Bool("null-io"))
|
task, err := newTask(ctx, client, container, context.String("checkpoint"), tty, context.Bool("null-io"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var statusC <-chan containerd.ExitStatus
|
||||||
|
if !detach {
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
if statusC, err = task.Wait(ctx); err != nil {
|
||||||
statusC, err := task.Wait(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var con console.Console
|
var con console.Console
|
||||||
if tty {
|
if tty {
|
||||||
con = console.Current()
|
con = console.Current()
|
||||||
@ -147,6 +152,9 @@ var runCommand = cli.Command{
|
|||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if detach {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if tty {
|
if tty {
|
||||||
if err := handleConsoleResize(ctx, task, con); err != nil {
|
if err := handleConsoleResize(ctx, task, con); err != nil {
|
||||||
logrus.WithError(err).Error("console resize")
|
logrus.WithError(err).Error("console resize")
|
||||||
@ -155,7 +163,6 @@ var runCommand = cli.Command{
|
|||||||
sigc := forwardAllSignals(ctx, task)
|
sigc := forwardAllSignals(ctx, task)
|
||||||
defer stopCatch(sigc)
|
defer stopCatch(sigc)
|
||||||
}
|
}
|
||||||
|
|
||||||
status := <-statusC
|
status := <-statusC
|
||||||
code, _, err := status.Result()
|
code, _, err := status.Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,7 +46,7 @@ var taskStartCommand = cli.Command{
|
|||||||
|
|
||||||
tty := spec.Process.Terminal
|
tty := spec.Process.Terminal
|
||||||
|
|
||||||
task, err := newTask(ctx, container, "", tty, context.Bool("null-io"))
|
task, err := newTask(ctx, client, container, "", tty, context.Bool("null-io"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user