github.com/xuyutom/docker@v1.6.0/graph/history.go (about) 1 package graph 2 3 import ( 4 "strings" 5 6 "github.com/docker/docker/engine" 7 "github.com/docker/docker/image" 8 "github.com/docker/docker/utils" 9 ) 10 11 func (s *TagStore) CmdHistory(job *engine.Job) engine.Status { 12 if n := len(job.Args); n != 1 { 13 return job.Errorf("Usage: %s IMAGE", job.Name) 14 } 15 name := job.Args[0] 16 foundImage, err := s.LookupImage(name) 17 if err != nil { 18 return job.Error(err) 19 } 20 21 lookupMap := make(map[string][]string) 22 for name, repository := range s.Repositories { 23 for tag, id := range repository { 24 // If the ID already has a reverse lookup, do not update it unless for "latest" 25 if _, exists := lookupMap[id]; !exists { 26 lookupMap[id] = []string{} 27 } 28 lookupMap[id] = append(lookupMap[id], utils.ImageReference(name, tag)) 29 } 30 } 31 32 outs := engine.NewTable("Created", 0) 33 err = foundImage.WalkHistory(func(img *image.Image) error { 34 out := &engine.Env{} 35 out.SetJson("Id", img.ID) 36 out.SetInt64("Created", img.Created.Unix()) 37 out.Set("CreatedBy", strings.Join(img.ContainerConfig.Cmd, " ")) 38 out.SetList("Tags", lookupMap[img.ID]) 39 out.SetInt64("Size", img.Size) 40 outs.Add(out) 41 return nil 42 }) 43 if _, err := outs.WriteListTo(job.Stdout); err != nil { 44 return job.Error(err) 45 } 46 return engine.StatusOK 47 }