2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdExport exports a filesystem as a tar archive.
|
|
|
|
//
|
|
|
|
// The tar archive is streamed to STDOUT by default or written to a file.
|
|
|
|
//
|
|
|
|
// Usage: docker export [OPTIONS] CONTAINER
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdExport(args ...string) error {
|
|
|
|
cmd := cli.Subcmd("export", "CONTAINER", "Export a filesystem as a tar archive (streamed to STDOUT by default)", true)
|
|
|
|
outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT")
|
|
|
|
cmd.Require(flag.Exact, 1)
|
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
var (
|
|
|
|
output io.Writer = cli.out
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if *outfile != "" {
|
|
|
|
output, err = os.Create(*outfile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else if cli.isTerminalOut {
|
|
|
|
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
|
|
|
|
}
|
|
|
|
|
2015-04-27 00:41:03 -04:00
|
|
|
image := cmd.Arg(0)
|
2015-05-01 14:23:44 -04:00
|
|
|
sopts := &streamOpts{
|
|
|
|
rawTerminal: true,
|
|
|
|
out: output,
|
|
|
|
}
|
|
|
|
if err := cli.stream("GET", "/containers/"+image+"/export", sopts); err != nil {
|
2015-04-27 00:41:03 -04:00
|
|
|
return err
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|