From 5127732c7911988c81eda7bb31ac77fc1dd36ac2 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 19 Mar 2014 14:30:13 -0400 Subject: [PATCH 1/3] docker save: --output flag for those that do not care to redirect stdout Docker-DCO-1.1-Signed-off-by: Vincent Batts (github: vbatts) --- api/client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/client.go b/api/client.go index 8f515639a7..343a24078c 100644 --- a/api/client.go +++ b/api/client.go @@ -2044,6 +2044,8 @@ 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)") + outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT") + if err := cmd.Parse(args); err != nil { return err } @@ -2053,8 +2055,16 @@ func (cli *DockerCli) CmdSave(args ...string) error { return nil } + var output io.Writer = cli.out + var 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 From e93a16ab48f75311aab155548f32776cbd21dfe6 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 19 Mar 2014 14:47:20 -0400 Subject: [PATCH 2/3] docker save: add and improve docs add usage examples for `docker save ...` Docker-DCO-1.1-Signed-off-by: Vincent Batts (github: vbatts) --- api/client.go | 2 +- docs/sources/reference/commandline/cli.rst | 23 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api/client.go b/api/client.go index 343a24078c..5a69700704 100644 --- a/api/client.go +++ b/api/client.go @@ -2043,7 +2043,7 @@ 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 { diff --git a/docs/sources/reference/commandline/cli.rst b/docs/sources/reference/commandline/cli.rst index 0f33b05ec4..294e1d0544 100644 --- a/docs/sources/reference/commandline/cli.rst +++ b/docs/sources/reference/commandline/cli.rst @@ -1307,10 +1307,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: From 78a0105eaf80ed85e2ee236632a2cc16998228f9 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 19 Mar 2014 17:09:12 -0400 Subject: [PATCH 3/3] api/client: var style tweak Docker-DCO-1.1-Signed-off-by: Vincent Batts (github: vbatts) --- api/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/client.go b/api/client.go index 5a69700704..e7abf04cb5 100644 --- a/api/client.go +++ b/api/client.go @@ -2055,8 +2055,10 @@ func (cli *DockerCli) CmdSave(args ...string) error { return nil } - var output io.Writer = cli.out - var err error + var ( + output io.Writer = cli.out + err error + ) if *outfile != "" { output, err = os.Create(*outfile) if err != nil {