Merge pull request #10105 from LK4D4/remove_tons_of_names

Use graphdb.Walk with depth=1 in /containers
This commit is contained in:
Michael Crosby 2015-02-06 14:33:26 -08:00
commit 9d140fe693
3 changed files with 32 additions and 6 deletions

View file

@ -54,12 +54,11 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
}
}
}
names := map[string][]string{}
daemon.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
names[e.ID()] = append(names[e.ID()], p)
return nil
}, -1)
}, 1)
var beforeCont, sinceCont *Container
if before != "" {

View file

@ -1433,12 +1433,12 @@ The `docker rename` command allows the container to be renamed to a different na
-s, --size=false Display total file sizes
--since="" Show created since Id or Name, include non-running.
Running `docker ps` showing 2 linked containers.
Running `docker ps --no-trunc` showing 2 linked containers.
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f7ee772232194fcc088c6bdec6ea09f7b3f6c54d53934658164b8602d7cd4744 ubuntu:12.04 bash 17 seconds ago Up 16 seconds webapp
d0963715a061c7c7b7cc80b2646da913a959fbf13e80a971d4a60f6997a2f595 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db
`docker ps` will show only running containers by default. To see all containers:
`docker ps -a`

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os/exec"
"reflect"
"strconv"
"strings"
"testing"
@ -539,3 +540,29 @@ func TestPsRightTagName(t *testing.T) {
}
logDone("ps - right tags for containers")
}
func TestPsLinkedWithNoTrunc(t *testing.T) {
defer deleteAllContainers()
if out, err := exec.Command(dockerBinary, "run", "--name=first", "-d", "busybox", "top").CombinedOutput(); err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
if out, err := exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "-d", "busybox", "top").CombinedOutput(); err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
out, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
if err != nil {
t.Fatalf("Output: %s, err: %s", out, err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// strip header
lines = lines[1:]
expected := []string{"second", "first,second/first"}
var names []string
for _, l := range lines {
fields := strings.Fields(l)
names = append(names, fields[len(fields)-1])
}
if !reflect.DeepEqual(expected, names) {
t.Fatalf("Expected array: %v, got: %v", expected, names)
}
}