diff --git a/api.go b/api.go index d387bce618..6929bbd6e0 100644 --- a/api.go +++ b/api.go @@ -102,14 +102,9 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request) ([ vars := mux.Vars(r) name := vars["name"] - in, out, err := hijackServer(w) - if err != nil { - return nil, err - } - defer in.Close() - fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - if err := srv.ContainerExport(name, out); err != nil { - fmt.Fprintf(out, "Error: %s\n", err) + if err := srv.ContainerExport(name, w); err != nil { + Debugf("%s", err.Error()) + //return nil, err } return nil, nil } diff --git a/commands.go b/commands.go index 44eddd2af1..63a1f3ed36 100644 --- a/commands.go +++ b/commands.go @@ -865,7 +865,7 @@ func CmdExport(args ...string) error { return nil } - if err := hijack("GET", "/containers/"+cmd.Arg(0)+"/export", false); err != nil { + if err := stream("GET", "/containers/"+cmd.Arg(0)+"/export"); err != nil { return err } return nil @@ -1180,6 +1180,29 @@ func call(method, path string, data interface{}) ([]byte, int, error) { return body, resp.StatusCode, nil } +func stream(method, path string) error { + req, err := http.NewRequest(method, "http://0.0.0.0:4243"+path, nil) + if err != nil { + return err + } + req.Header.Set("User-Agent", "Docker-Client/"+VERSION) + if method == "POST" { + req.Header.Set("Content-Type", "plain/text") + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + if strings.Contains(err.Error(), "connection refused") { + return fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?") + } + return err + } + defer resp.Body.Close() + if _, err := io.Copy(os.Stdout, resp.Body); err != nil { + return err + } + return nil +} + func hijack(method, path string, setRawTerminal bool) error { req, err := http.NewRequest(method, path, nil) if err != nil { diff --git a/docs/sources/remote-api/api.rst b/docs/sources/remote-api/api.rst index 350d6c5894..0e9ded548b 100644 --- a/docs/sources/remote-api/api.rst +++ b/docs/sources/remote-api/api.rst @@ -262,7 +262,7 @@ Export a container .. sourcecode:: http HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream + Content-Type: application/octet-stream {{ STREAM }}