github.com/rentongzhang/docker@v1.8.2-rc1/api/client/export.go (about) 1 package client 2 3 import ( 4 "errors" 5 "io" 6 "os" 7 8 Cli "github.com/docker/docker/cli" 9 flag "github.com/docker/docker/pkg/mflag" 10 ) 11 12 // CmdExport exports a filesystem as a tar archive. 13 // 14 // The tar archive is streamed to STDOUT by default or written to a file. 15 // 16 // Usage: docker export [OPTIONS] CONTAINER 17 func (cli *DockerCli) CmdExport(args ...string) error { 18 cmd := Cli.Subcmd("export", []string{"CONTAINER"}, "Export the contents of a container's filesystem as a tar archive", true) 19 outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT") 20 cmd.Require(flag.Exact, 1) 21 22 cmd.ParseFlags(args, true) 23 24 var ( 25 output io.Writer = cli.out 26 err error 27 ) 28 if *outfile != "" { 29 output, err = os.Create(*outfile) 30 if err != nil { 31 return err 32 } 33 } else if cli.isTerminalOut { 34 return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") 35 } 36 37 image := cmd.Arg(0) 38 sopts := &streamOpts{ 39 rawTerminal: true, 40 out: output, 41 } 42 if _, err := cli.stream("GET", "/containers/"+image+"/export", sopts); err != nil { 43 return err 44 } 45 46 return nil 47 }