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