Files
docker-cli/cli/command/checkpoint/create.go
Sebastiaan van Stijn b55fed5ef6 vendor: github.com/moby/moby/api v1.52.0-beta.1, client v0.1.0-beta.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Co-authored-by: Austin Vazquez <austin.vazquez@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-05 22:41:03 +02:00

56 lines
1.4 KiB
Go

package checkpoint
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
type createOptions struct {
container string
checkpoint string
checkpointDir string
leaveRunning bool
}
func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
var opts createOptions
cmd := &cobra.Command{
Use: "create [OPTIONS] CONTAINER CHECKPOINT",
Short: "Create a checkpoint from a running container",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
opts.checkpoint = args[1]
return runCreate(cmd.Context(), dockerCLI, opts)
},
ValidArgsFunction: cobra.NoFileCompletions,
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.BoolVar(&opts.leaveRunning, "leave-running", false, "Leave the container running after checkpoint")
flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory")
return cmd
}
func runCreate(ctx context.Context, dockerCLI command.Cli, opts createOptions) error {
err := dockerCLI.Client().CheckpointCreate(ctx, opts.container, client.CheckpointCreateOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
Exit: !opts.leaveRunning,
})
if err != nil {
return err
}
_, _ = fmt.Fprintln(dockerCLI.Out(), opts.checkpoint)
return nil
}