Merge pull request #4778 from vbatts/vbatts-save_to_output

`docker save --output` flags
This commit is contained in:
Michael Crosby 2014-03-24 16:52:08 -07:00
commit a258d048a2
2 changed files with 34 additions and 5 deletions

View file

@ -2044,7 +2044,9 @@ func (cli *DockerCli) CmdCp(args ...string) error {
}
func (cli *DockerCli) CmdSave(args ...string) error {
cmd := cli.Subcmd("save", "IMAGE", "Save an image to a tar archive (streamed to stdout)")
cmd := cli.Subcmd("save", "IMAGE", "Save an image to a tar archive (streamed to stdout by default)")
outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
if err := cmd.Parse(args); err != nil {
return err
}
@ -2054,8 +2056,18 @@ func (cli *DockerCli) CmdSave(args ...string) error {
return nil
}
var (
output io.Writer = cli.out
err error
)
if *outfile != "" {
output, err = os.Create(*outfile)
if err != nil {
return err
}
}
image := cmd.Arg(0)
if err := cli.stream("GET", "/images/"+image+"/get", nil, cli.out, nil); err != nil {
if err := cli.stream("GET", "/images/"+image+"/get", nil, output, nil); err != nil {
return err
}
return nil

View file

@ -1317,10 +1317,27 @@ This example shows 5 containers that might be set up to test a web application c
::
Usage: docker save image > repository.tar
Usage: docker save IMAGE
Save an image to a tar archive (streamed to stdout by default)
-o, --output="": Write to an file, instead of STDOUT
Produces a tarred repository to the standard output stream.
Contains all parent layers, and all tags + versions, or specified repo:tag.
.. code-block:: bash
$ sudo docker save busybox > busybox.tar
$ ls -sh b.tar
2.7M b.tar
$ sudo docker save --output busybox.tar busybox
$ ls -sh b.tar
2.7M b.tar
$ sudo docker save -o fedora-all.tar fedora
$ sudo docker save -o fedora-latest.tar fedora:latest
Streams a tarred repository to the standard output stream.
Contains all parent layers, and all tags + versions.
.. _cli_search: