Skip to content

Commit

Permalink
Merge pull request #9985 from jfrazelle/fix-exited-filter-should-not-…
Browse files Browse the repository at this point in the history
…show-running

`docker ps --filter exited=status` should not show running containers
  • Loading branch information
vbatts committed Jan 12, 2015
2 parents a52c3a7 + 81f8402 commit 3ec6959
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 2 additions & 3 deletions daemon/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
if !container.Running && !all && n <= 0 && since == "" && before == "" {
return nil
}

if !psFilters.Match("name", container.Name) {
return nil
}
Expand All @@ -104,10 +103,10 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
return errLast
}
}
if len(filt_exited) > 0 && !container.Running {
if len(filt_exited) > 0 {
should_skip := true
for _, code := range filt_exited {
if code == container.ExitCode {
if code == container.ExitCode && !container.Running {
should_skip = false
break
}
Expand Down
24 changes: 13 additions & 11 deletions integration-cli/docker_cli_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,15 @@ func TestPsListContainersFilterName(t *testing.T) {
}

func TestPsListContainersFilterExited(t *testing.T) {
deleteAllContainers()
defer deleteAllContainers()
runCmd := exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {

runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}

runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
firstZero, err := getIDByName("zero1")
Expand All @@ -411,8 +415,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
}

runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
secondZero, err := getIDByName("zero2")
Expand All @@ -421,8 +424,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
}

runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
out, _, err = runCommandWithOutput(runCmd)
if err == nil {
if out, _, err := runCommandWithOutput(runCmd); err == nil {
t.Fatal("Should fail.", out, err)
}
firstNonZero, err := getIDByName("nonzero1")
Expand All @@ -431,8 +433,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
}

runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
out, _, err = runCommandWithOutput(runCmd)
if err == nil {
if out, _, err := runCommandWithOutput(runCmd); err == nil {
t.Fatal("Should fail.", out, err)
}
secondNonZero, err := getIDByName("nonzero2")
Expand All @@ -442,7 +443,7 @@ func TestPsListContainersFilterExited(t *testing.T) {

// filter containers by exited=0
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
out, _, err = runCommandWithOutput(runCmd)
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(out, err)
}
Expand Down Expand Up @@ -472,5 +473,6 @@ func TestPsListContainersFilterExited(t *testing.T) {
if ids[1] != firstNonZero {
t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
}

logDone("ps - test ps filter exited")
}

0 comments on commit 3ec6959

Please sign in to comment.