1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cli/command/checkpoint/create.go
boucher bd7d51292c Allow providing a custom storage directory for docker checkpoints
Signed-off-by: boucher <rboucher@gmail.com>
2016-10-28 07:56:05 -04:00

55 lines
1.3 KiB
Go

package checkpoint
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
)
type createOptions struct {
container string
checkpoint string
checkpointDir string
leaveRunning bool
}
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
var opts createOptions
cmd := &cobra.Command{
Use: "create 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(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.BoolVar(&opts.leaveRunning, "leave-running", false, "leave the container running after checkpoint")
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
return cmd
}
func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
client := dockerCli.Client()
checkpointOpts := types.CheckpointCreateOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
Exit: !opts.leaveRunning,
}
err := client.CheckpointCreate(context.Background(), opts.container, checkpointOpts)
if err != nil {
return err
}
return nil
}