2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdLoad loads an image from a tar archive.
|
|
|
|
//
|
|
|
|
// The tar archive is read from STDIN by default, or from a tar archive file.
|
|
|
|
//
|
|
|
|
// Usage: docker load [OPTIONS]
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdLoad(args ...string) error {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("load", nil, Cli.DockerCommands["load"].Description, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
|
|
|
|
cmd.Require(flag.Exact, 0)
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-03 18:49:55 -05:00
|
|
|
var input io.Reader = cli.in
|
2015-03-24 23:57:23 -04:00
|
|
|
if *infile != "" {
|
2015-12-03 18:49:55 -05:00
|
|
|
file, err := os.Open(*infile)
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-03 18:49:55 -05:00
|
|
|
defer file.Close()
|
|
|
|
input = file
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-12-03 18:49:55 -05:00
|
|
|
|
|
|
|
responseBody, err := cli.client.ImageLoad(input)
|
|
|
|
if err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
return err
|
|
|
|
}
|
2015-12-03 18:49:55 -05:00
|
|
|
defer responseBody.Close()
|
|
|
|
|
|
|
|
_, err = io.Copy(cli.out, responseBody)
|
|
|
|
return err
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|