mirror of https://github.com/docker/docs.git
'docker {history,ps,images}': show human-friendly image names when applicable
This commit is contained in:
parent
7952e6befe
commit
12049f956a
|
@ -311,7 +311,7 @@ func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout io.Writer, args ...str
|
||||||
fmt.Fprintf(w, "ID\tCREATED\tCREATED BY\n")
|
fmt.Fprintf(w, "ID\tCREATED\tCREATED BY\n")
|
||||||
return image.WalkHistory(func(img *Image) error {
|
return image.WalkHistory(func(img *Image) error {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\n",
|
fmt.Fprintf(w, "%s\t%s\t%s\n",
|
||||||
img.Id,
|
srv.runtime.repositories.ImageName(img.Id),
|
||||||
HumanDuration(time.Now().Sub(img.Created))+" ago",
|
HumanDuration(time.Now().Sub(img.Created))+" ago",
|
||||||
strings.Join(img.ParentCommand, " "),
|
strings.Join(img.ParentCommand, " "),
|
||||||
)
|
)
|
||||||
|
@ -514,7 +514,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
/* TAG */ tag,
|
/* TAG */ tag,
|
||||||
/* ID */ id,
|
/* ID */ id,
|
||||||
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago",
|
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago",
|
||||||
/* PARENT */ image.Parent,
|
/* PARENT */ srv.runtime.repositories.ImageName(image.Parent),
|
||||||
} {
|
} {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
w.Write([]byte(field))
|
w.Write([]byte(field))
|
||||||
|
@ -537,7 +537,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
/* TAG */ "",
|
/* TAG */ "",
|
||||||
/* ID */ id,
|
/* ID */ id,
|
||||||
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago",
|
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago",
|
||||||
/* PARENT */ image.Parent,
|
/* PARENT */ srv.runtime.repositories.ImageName(image.Parent),
|
||||||
} {
|
} {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
w.Write([]byte(field))
|
w.Write([]byte(field))
|
||||||
|
@ -581,7 +581,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
}
|
}
|
||||||
for idx, field := range []string{
|
for idx, field := range []string{
|
||||||
/* ID */ container.Id,
|
/* ID */ container.Id,
|
||||||
/* IMAGE */ container.Image,
|
/* IMAGE */ srv.runtime.repositories.ImageName(container.Image),
|
||||||
/* COMMAND */ command,
|
/* COMMAND */ command,
|
||||||
/* CREATED */ HumanDuration(time.Now().Sub(container.Created)) + " ago",
|
/* CREATED */ HumanDuration(time.Now().Sub(container.Created)) + " ago",
|
||||||
/* STATUS */ container.State.String(),
|
/* STATUS */ container.State.String(),
|
||||||
|
|
24
tags.go
24
tags.go
|
@ -83,6 +83,30 @@ func (store *TagStore) LookupImage(name string) (*Image, error) {
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a reverse-lookup table of all the names which refer to each image
|
||||||
|
// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
||||||
|
func (store *TagStore) ById() map[string][]string {
|
||||||
|
byId := make(map[string][]string)
|
||||||
|
for repoName, repository := range store.Repositories {
|
||||||
|
for tag, id := range repository {
|
||||||
|
name := repoName + ":" + tag
|
||||||
|
if _, exists := byId[id]; !exists {
|
||||||
|
byId[id] = []string{name}
|
||||||
|
} else {
|
||||||
|
byId[id] = append(byId[id], name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return byId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *TagStore) ImageName(id string) string {
|
||||||
|
if names, exists := store.ById()[id]; exists && len(names) > 0 {
|
||||||
|
return names[0]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
||||||
img, err := store.LookupImage(imageName)
|
img, err := store.LookupImage(imageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue