| ... | ... |
@@ -311,7 +311,7 @@ func (srv *Server) CmdHistory(stdin io.ReadCloser, stdout io.Writer, args ...str |
| 311 | 311 |
fmt.Fprintf(w, "ID\tCREATED\tCREATED BY\n") |
| 312 | 312 |
return image.WalkHistory(func(img *Image) error {
|
| 313 | 313 |
fmt.Fprintf(w, "%s\t%s\t%s\n", |
| 314 |
- img.Id, |
|
| 314 |
+ srv.runtime.repositories.ImageName(img.Id), |
|
| 315 | 315 |
HumanDuration(time.Now().Sub(img.Created))+" ago", |
| 316 | 316 |
strings.Join(img.ParentCommand, " "), |
| 317 | 317 |
) |
| ... | ... |
@@ -514,7 +514,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri |
| 514 | 514 |
/* TAG */ tag, |
| 515 | 515 |
/* ID */ id, |
| 516 | 516 |
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago", |
| 517 |
- /* PARENT */ image.Parent, |
|
| 517 |
+ /* PARENT */ srv.runtime.repositories.ImageName(image.Parent), |
|
| 518 | 518 |
} {
|
| 519 | 519 |
if idx == 0 {
|
| 520 | 520 |
w.Write([]byte(field)) |
| ... | ... |
@@ -537,7 +537,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri |
| 537 | 537 |
/* TAG */ "", |
| 538 | 538 |
/* ID */ id, |
| 539 | 539 |
/* CREATED */ HumanDuration(time.Now().Sub(image.Created)) + " ago", |
| 540 |
- /* PARENT */ image.Parent, |
|
| 540 |
+ /* PARENT */ srv.runtime.repositories.ImageName(image.Parent), |
|
| 541 | 541 |
} {
|
| 542 | 542 |
if idx == 0 {
|
| 543 | 543 |
w.Write([]byte(field)) |
| ... | ... |
@@ -581,7 +581,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) |
| 581 | 581 |
} |
| 582 | 582 |
for idx, field := range []string{
|
| 583 | 583 |
/* ID */ container.Id, |
| 584 |
- /* IMAGE */ container.Image, |
|
| 584 |
+ /* IMAGE */ srv.runtime.repositories.ImageName(container.Image), |
|
| 585 | 585 |
/* COMMAND */ command, |
| 586 | 586 |
/* CREATED */ HumanDuration(time.Now().Sub(container.Created)) + " ago", |
| 587 | 587 |
/* STATUS */ container.State.String(), |
| ... | ... |
@@ -83,6 +83,30 @@ func (store *TagStore) LookupImage(name string) (*Image, error) {
|
| 83 | 83 |
return img, nil |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 |
+// Return a reverse-lookup table of all the names which refer to each image |
|
| 87 |
+// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
|
| 88 |
+func (store *TagStore) ById() map[string][]string {
|
|
| 89 |
+ byId := make(map[string][]string) |
|
| 90 |
+ for repoName, repository := range store.Repositories {
|
|
| 91 |
+ for tag, id := range repository {
|
|
| 92 |
+ name := repoName + ":" + tag |
|
| 93 |
+ if _, exists := byId[id]; !exists {
|
|
| 94 |
+ byId[id] = []string{name}
|
|
| 95 |
+ } else {
|
|
| 96 |
+ byId[id] = append(byId[id], name) |
|
| 97 |
+ } |
|
| 98 |
+ } |
|
| 99 |
+ } |
|
| 100 |
+ return byId |
|
| 101 |
+} |
|
| 102 |
+ |
|
| 103 |
+func (store *TagStore) ImageName(id string) string {
|
|
| 104 |
+ if names, exists := store.ById()[id]; exists && len(names) > 0 {
|
|
| 105 |
+ return names[0] |
|
| 106 |
+ } |
|
| 107 |
+ return id |
|
| 108 |
+} |
|
| 109 |
+ |
|
| 86 | 110 |
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
| 87 | 111 |
img, err := store.LookupImage(imageName) |
| 88 | 112 |
if err != nil {
|