Use image ID if tag has been updated
Fixes #12595 Signed-off-by: Travis Thieman <travis.thieman@gmail.com>
This commit is contained in:
parent
7ead74d903
commit
2167f40a76
|
@ -136,7 +136,18 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,
|
|||
ID: 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 {
|
||||
args := []string{}
|
||||
for _, arg := range container.Args {
|
||||
|
|
|
@ -573,3 +573,57 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
|||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue