mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
docker save: raw json
Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
parent
6228761f67
commit
d3bc787bca
2 changed files with 17 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue