github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/checkpoint/create.go (about) 1 // +build experimental 2 3 package checkpoint 4 5 import ( 6 "golang.org/x/net/context" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/cli" 10 "github.com/docker/docker/cli/command" 11 "github.com/spf13/cobra" 12 ) 13 14 type createOptions struct { 15 container string 16 checkpoint string 17 leaveRunning bool 18 } 19 20 func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { 21 var opts createOptions 22 23 cmd := &cobra.Command{ 24 Use: "create CONTAINER CHECKPOINT", 25 Short: "Create a checkpoint from a running container", 26 Args: cli.ExactArgs(2), 27 RunE: func(cmd *cobra.Command, args []string) error { 28 opts.container = args[0] 29 opts.checkpoint = args[1] 30 return runCreate(dockerCli, opts) 31 }, 32 } 33 34 flags := cmd.Flags() 35 flags.BoolVar(&opts.leaveRunning, "leave-running", false, "leave the container running after checkpoint") 36 37 return cmd 38 } 39 40 func runCreate(dockerCli *command.DockerCli, opts createOptions) error { 41 client := dockerCli.Client() 42 43 checkpointOpts := types.CheckpointCreateOptions{ 44 CheckpointID: opts.checkpoint, 45 Exit: !opts.leaveRunning, 46 } 47 48 err := client.CheckpointCreate(context.Background(), opts.container, checkpointOpts) 49 if err != nil { 50 return err 51 } 52 53 return nil 54 }