github.com/rentongzhang/docker@v1.8.2-rc1/api/client/load.go (about) 1 package client 2 3 import ( 4 "io" 5 "os" 6 7 Cli "github.com/docker/docker/cli" 8 flag "github.com/docker/docker/pkg/mflag" 9 ) 10 11 // CmdLoad loads an image from a tar archive. 12 // 13 // The tar archive is read from STDIN by default, or from a tar archive file. 14 // 15 // Usage: docker load [OPTIONS] 16 func (cli *DockerCli) CmdLoad(args ...string) error { 17 cmd := Cli.Subcmd("load", nil, "Load an image from a tar archive or STDIN", true) 18 infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN") 19 cmd.Require(flag.Exact, 0) 20 21 cmd.ParseFlags(args, true) 22 23 var ( 24 input io.Reader = cli.in 25 err error 26 ) 27 if *infile != "" { 28 input, err = os.Open(*infile) 29 if err != nil { 30 return err 31 } 32 } 33 sopts := &streamOpts{ 34 rawTerminal: true, 35 in: input, 36 out: cli.out, 37 } 38 if _, err := cli.stream("POST", "/images/load", sopts); err != nil { 39 return err 40 } 41 return nil 42 }