1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Show right tag for container in ps

Fixes #10599

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-02-05 14:55:08 -08:00
parent abdfb21e3a
commit e45deceb46
2 changed files with 57 additions and 1 deletions

View file

@ -6,9 +6,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/docker/docker/graph"
"github.com/docker/docker/pkg/graphdb" "github.com/docker/docker/pkg/graphdb"
"github.com/docker/docker/engine" "github.com/docker/docker/engine"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/parsers/filters" "github.com/docker/docker/pkg/parsers/filters"
) )
@ -123,7 +125,12 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
out := &engine.Env{} out := &engine.Env{}
out.SetJson("Id", container.ID) out.SetJson("Id", container.ID)
out.SetList("Names", names[container.ID]) out.SetList("Names", names[container.ID])
out.SetJson("Image", daemon.Repositories().ImageName(container.ImageID)) img := container.Config.Image
_, tag := parsers.ParseRepositoryTag(container.Config.Image)
if tag == "" {
img = img + ":" + graph.DEFAULTTAG
}
out.SetJson("Image", img)
if len(container.Args) > 0 { if len(container.Args) > 0 {
args := []string{} args := []string{}
for _, arg := range container.Args { for _, arg := range container.Args {

View file

@ -490,3 +490,52 @@ func TestPsListContainersFilterExited(t *testing.T) {
logDone("ps - test ps filter exited") logDone("ps - test ps filter exited")
} }
func TestPsRightTagName(t *testing.T) {
tag := "asybox:shmatest"
defer deleteAllContainers()
defer deleteImages(tag)
if out, err := exec.Command(dockerBinary, "tag", "busybox", tag).CombinedOutput(); err != nil {
t.Fatalf("Failed to tag image: %s, out: %q", err, out)
}
var id1 string
if out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "top").CombinedOutput(); err != nil {
t.Fatalf("Failed to run container: %s, out: %q", err, out)
} else {
id1 = strings.TrimSpace(string(out))
}
var id2 string
if out, err := exec.Command(dockerBinary, "run", "-d", tag, "top").CombinedOutput(); err != nil {
t.Fatalf("Failed to run container: %s, out: %q", err, out)
} else {
id2 = strings.TrimSpace(string(out))
}
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
if err != nil {
t.Fatalf("Failed to run 'ps': %s, out: %q", err, out)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// skip header
lines = lines[1:]
if len(lines) != 2 {
t.Fatalf("There should be 2 running container, got %d", len(lines))
}
for _, line := range lines {
f := strings.Fields(line)
switch f[0] {
case id1:
if f[1] != "busybox:latest" {
t.Fatalf("Expected %s tag for id %s, got %s", "busybox", id1, f[1])
}
case id2:
if f[1] != tag {
t.Fatalf("Expected %s tag for id %s, got %s", tag, id1, f[1])
}
default:
t.Fatalf("Unexpected id %s, expected %s and %s", f[0], id1, id2)
}
}
logDone("ps - right tags for containers")
}