Merge pull request #10601 from LK4D4/fix_tag_name_in_ps
Show right tag for container in ps
This commit is contained in:
commit
a982432c16
2 changed files with 57 additions and 1 deletions
|
@ -6,9 +6,11 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/pkg/graphdb"
|
||||
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
)
|
||||
|
||||
|
@ -123,7 +125,12 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
|
|||
out := &engine.Env{}
|
||||
out.SetJson("Id", 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 {
|
||||
args := []string{}
|
||||
for _, arg := range container.Args {
|
||||
|
|
|
@ -490,3 +490,52 @@ func TestPsListContainersFilterExited(t *testing.T) {
|
|||
|
||||
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")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue