diff --git a/api/server/server.go b/api/server/server.go index 6deb88f827..1e3ad78c50 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -738,6 +738,15 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w } } + var ( + opErr error + useJSON = version.GreaterThan("1.0") + ) + + if useJSON { + w.Header().Set("Content-Type", "application/json") + } + if image != "" { //pull if tag == "" { image, tag = parsers.ParseRepositoryTag(image) @@ -754,17 +763,10 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w MetaHeaders: metaHeaders, AuthConfig: authConfig, OutStream: utils.NewWriteFlusher(w), - } - if version.GreaterThan("1.0") { - imagePullConfig.Json = true - w.Header().Set("Content-Type", "application/json") - } else { - imagePullConfig.Json = false + Json: useJSON, } - if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig); err != nil { - return err - } + opErr = s.daemon.Repositories().Pull(image, tag, imagePullConfig) } else { //import if tag == "" { repo, tag = parsers.ParseRepositoryTag(repo) @@ -775,12 +777,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w Changes: r.Form["changes"], InConfig: r.Body, OutStream: utils.NewWriteFlusher(w), - } - if version.GreaterThan("1.0") { - imageImportConfig.Json = true - w.Header().Set("Content-Type", "application/json") - } else { - imageImportConfig.Json = false + Json: useJSON, } newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes) @@ -789,9 +786,12 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w } imageImportConfig.ContainerConfig = newConfig - if err := s.daemon.Repositories().Import(src, repo, tag, imageImportConfig); err != nil { - return err - } + opErr = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig) + } + + if opErr != nil { + sf := streamformatter.NewStreamFormatter(useJSON) + return fmt.Errorf(string(sf.FormatError(opErr))) } return nil diff --git a/integration-cli/docker_cli_pull_test.go b/integration-cli/docker_cli_pull_test.go index 8cf09a7261..25a93729b4 100644 --- a/integration-cli/docker_cli_pull_test.go +++ b/integration-cli/docker_cli_pull_test.go @@ -98,8 +98,13 @@ func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) { // pulling a non-existing image from the central registry should return a non-zero exit code func (s *DockerSuite) TestPullNonExistingImage(c *check.C) { - pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234") - if out, _, err := runCommandWithOutput(pullCmd); err == nil { + testRequires(c, Network) + + name := "sadfsadfasdf" + pullCmd := exec.Command(dockerBinary, "pull", name) + out, _, err := runCommandWithOutput(pullCmd) + + if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) { c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out) } }