Selaa lähdekoodia

Merge pull request #10105 from LK4D4/remove_tons_of_names

Use graphdb.Walk with depth=1 in /containers
Michael Crosby 10 vuotta sitten
vanhempi
commit
9d140fe693

+ 1 - 2
daemon/list.go

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

+ 4 - 4
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
       -s, --size=false      Display total file sizes
       --since=""            Show created since Id or Name, include non-running.
       --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
     $ 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` will show only running containers by default. To see all containers:
 `docker ps -a`
 `docker ps -a`

+ 27 - 0
integration-cli/docker_cli_ps_test.go

@@ -3,6 +3,7 @@ package main
 import (
 import (
 	"fmt"
 	"fmt"
 	"os/exec"
 	"os/exec"
+	"reflect"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -539,3 +540,29 @@ func TestPsRightTagName(t *testing.T) {
 	}
 	}
 	logDone("ps - right tags for containers")
 	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)
+	}
+}