diff --git a/daemon/container.go b/daemon/container.go index 2d9487ea68..d18db430a9 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -203,7 +203,7 @@ func (container *Container) LogEvent(action string) { d.EventsService.Log( action, container.ID, - d.Repositories().ImageName(container.ImageID), + container.Config.Image, ) } diff --git a/daemon/list.go b/daemon/list.go index 511b49605d..99242988b0 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -7,12 +7,9 @@ import ( "strings" "github.com/docker/docker/api/types" - "github.com/docker/docker/graph" "github.com/docker/docker/nat" "github.com/docker/docker/pkg/graphdb" - "github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers/filters" - "github.com/docker/docker/utils" ) // List returns an array of all containers registered in the daemon. @@ -136,12 +133,7 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container, ID: container.ID, Names: names[container.ID], } - img := container.Config.Image - _, tag := parsers.ParseRepositoryTag(container.Config.Image) - if tag == "" { - img = utils.ImageReference(img, graph.DEFAULTTAG) - } - newC.Image = img + newC.Image = container.Config.Image if len(container.Args) > 0 { args := []string{} for _, arg := range container.Args { diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index bea9bf9378..e3f7ec7f16 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -2009,8 +2009,16 @@ func TestBuildCancelationKillsSleep(t *testing.T) { }() var started, died bool - matchStart := regexp.MustCompile(" \\(from busybox\\:latest\\) start$") - matchDie := regexp.MustCompile(" \\(from busybox\\:latest\\) die$") + var imageID string + + if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil { + t.Fatalf("failed to get the image ID of busybox: %s, %v", out, err) + } else { + imageID = strings.TrimSpace(string(out)) + } + + matchStart := regexp.MustCompile(" \\(from " + imageID + "\\) start$") + matchDie := regexp.MustCompile(" \\(from " + imageID + "\\) die$") // // Read lines of `docker events` looking for container start and stop. diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 97e3095137..2021abc2a9 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -290,7 +290,7 @@ func TestEventsFilterImageName(t *testing.T) { since := daemonTime(t).Unix() defer deleteAllContainers() - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox", "true")) + out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox:latest", "true")) if err != nil { t.Fatal(out, err) } @@ -302,30 +302,30 @@ func TestEventsFilterImageName(t *testing.T) { } container2 := strings.TrimSpace(out) - for _, s := range []string{"busybox", "busybox:latest"} { - eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("image=%s", s)) - out, _, err := runCommandWithOutput(eventsCmd) - if err != nil { - t.Fatalf("Failed to get events, error: %s(%s)", err, out) - } - events := strings.Split(out, "\n") - events = events[:len(events)-1] - if len(events) == 0 { - t.Fatalf("Expected events but found none for the image busybox:latest") - } - count1 := 0 - count2 := 0 - for _, e := range events { - if strings.Contains(e, container1) { - count1++ - } else if strings.Contains(e, container2) { - count2++ - } - } - if count1 == 0 || count2 == 0 { - t.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2) + s := "busybox" + eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("image=%s", s)) + out, _, err = runCommandWithOutput(eventsCmd) + if err != nil { + t.Fatalf("Failed to get events, error: %s(%s)", err, out) + } + events := strings.Split(out, "\n") + events = events[:len(events)-1] + if len(events) == 0 { + t.Fatalf("Expected events but found none for the image busybox:latest") + } + count1 := 0 + count2 := 0 + + for _, e := range events { + if strings.Contains(e, container1) { + count1++ + } else if strings.Contains(e, container2) { + count2++ } } + if count1 == 0 || count2 == 0 { + t.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2) + } logDone("events - filters using image") } @@ -467,7 +467,7 @@ func TestEventsStreaming(t *testing.T) { } }() - runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox:latest", "true") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatal(out, err) diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index f97da5be3f..9ac3474102 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -594,6 +594,21 @@ func TestPsRightTagName(t *testing.T) { } else { id2 = strings.TrimSpace(string(out)) } + + var imageID string + if out, err := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox").CombinedOutput(); err != nil { + t.Fatalf("failed to get the image ID of busybox: %s, %v", out, err) + } else { + imageID = strings.TrimSpace(string(out)) + } + + var id3 string + if out, err := exec.Command(dockerBinary, "run", "-d", imageID, "top").CombinedOutput(); err != nil { + t.Fatalf("Failed to run container: %s, out: %q", err, out) + } else { + id3 = 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) @@ -601,22 +616,26 @@ func TestPsRightTagName(t *testing.T) { 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)) + if len(lines) != 3 { + t.Fatalf("There should be 3 running container, got %d", len(lines)) } for _, line := range lines { f := strings.Fields(line) switch f[0] { case id1: - if f[1] != "busybox:latest" { + if f[1] != "busybox" { 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]) + t.Fatalf("Expected %s tag for id %s, got %s", tag, id2, f[1]) + } + case id3: + if f[1] != imageID { + t.Fatalf("Expected %s imageID for id %s, got %s", tag, id3, f[1]) } default: - t.Fatalf("Unexpected id %s, expected %s and %s", f[0], id1, id2) + t.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3) } } logDone("ps - right tags for containers")