Use image ID if tag has been updated

Fixes #12595

Signed-off-by: Travis Thieman <travis.thieman@gmail.com>
This commit is contained in:
Travis Thieman 2015-04-30 21:13:18 -04:00
parent 7ead74d903
commit 2167f40a76
2 changed files with 66 additions and 1 deletions

View File

@ -136,7 +136,18 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,
ID: container.ID, ID: container.ID,
Names: names[container.ID], Names: names[container.ID],
} }
newC.Image = container.Config.Image
img, err := daemon.Repositories().LookupImage(container.Config.Image)
if err != nil {
// If the image can no longer be found by its original reference,
// it makes sense to show the ID instead of a stale reference.
newC.Image = container.ImageID
} else if container.ImageID == img.ID {
newC.Image = container.Config.Image
} else {
newC.Image = container.ImageID
}
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

@ -573,3 +573,57 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
c.Fatalf("Expected to print only the container id, got %v\n", out) c.Fatalf("Expected to print only the container id, got %v\n", out)
} }
} }
// Test for GitHub issue #12595
func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
runCmd := exec.Command(dockerBinary, "tag", "busybox:latest", originalImageName)
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
originalImageID, err := getIDByName(originalImageName)
c.Assert(err, check.IsNil)
runCmd = exec.Command(dockerBinary, "run", "-d", originalImageName, "top")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
containerID := strings.TrimSpace(out)
linesOut, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
c.Assert(err, check.IsNil)
lines := strings.Split(strings.TrimSpace(string(linesOut)), "\n")
// skip header
lines = lines[1:]
c.Assert(len(lines), check.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], check.Equals, originalImageName)
}
runCmd = exec.Command(dockerBinary, "commit", containerID, updatedImageName)
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
runCmd = exec.Command(dockerBinary, "tag", "-f", updatedImageName, originalImageName)
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
linesOut, err = exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
c.Assert(err, check.IsNil)
lines = strings.Split(strings.TrimSpace(string(linesOut)), "\n")
// skip header
lines = lines[1:]
c.Assert(len(lines), check.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], check.Equals, originalImageID)
}
}