diff --git a/graph/service.go b/graph/service.go index ebdb881603..3201d6b994 100644 --- a/graph/service.go +++ b/graph/service.go @@ -1,7 +1,6 @@ package graph import ( - "encoding/json" "io" "github.com/dotcloud/docker/engine" @@ -136,7 +135,7 @@ func (s *TagStore) CmdLookup(job *engine.Job) engine.Status { name := job.Args[0] if image, err := s.LookupImage(name); err == nil && image != nil { if job.GetenvBool("raw") { - b, err := json.Marshal(image) + b, err := image.RawJson() if err != nil { return job.Error(err) } diff --git a/image/image.go b/image/image.go index b56cbf08ee..5c250947ce 100644 --- a/image/image.go +++ b/image/image.go @@ -149,6 +149,22 @@ func jsonPath(root string) string { return path.Join(root, "json") } +func (img *Image) RawJson() ([]byte, error) { + root, err := img.root() + if err != nil { + return nil, fmt.Errorf("Failed to get root for image %s: %s", img.ID, err) + } + fh, err := os.Open(jsonPath(root)) + if err != nil { + return nil, fmt.Errorf("Failed to open json for image %s: %s", img.ID, err) + } + buf, err := ioutil.ReadAll(fh) + if err != nil { + return nil, fmt.Errorf("Failed to read json for image %s: %s", img.ID, err) + } + return buf, nil +} + // TarLayer returns a tar archive of the image's filesystem layer. func (img *Image) TarLayer() (arch archive.Archive, err error) { if img.graph == nil {