From 10c3d9f80fa1584ea37eb0465748d35341d9d227 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Wed, 14 Jan 2015 15:26:42 -0800 Subject: [PATCH 1/3] Use graphdb.Walk with depth=1 in /containers I don't think that it was very useful feature in current implementation, but when you have a lot of links - your daemon became unusable because on first call of /containers global graphdb lock will be acquired and it can take a lot of time: 30m for 15 containers linked to each other. Links names can be seen with `--no-trunc`, but I think it's useless :) Fixes #9967 Signed-off-by: Alexander Morozov --- daemon/list.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/list.go b/daemon/list.go index 5ca01862e..5885ebd49 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -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 != "" { From 2a3225eb82274d245c25fc6191945dde1f25f668 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 15 Jan 2015 11:03:46 -0800 Subject: [PATCH 2/3] Test for links names in ps --no-trunc Signed-off-by: Alexander Morozov --- integration-cli/docker_cli_ps_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 89dbf23cd..b92c80416 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -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) + } +} From 0f8f04a77492ddf37ca9c163ef0c3ddaf8a93a40 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Thu, 15 Jan 2015 11:06:35 -0800 Subject: [PATCH 3/3] Fix example about ps and linked containers Signed-off-by: Alexander Morozov --- docs/sources/reference/commandline/cli.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index c572b3231..f7d0f5895 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -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`