Przeglądaj źródła

A fix for = in env values in linked containers

Closes: #12763

Signed-off-by: Doug Davis <dug@us.ibm.com>
Doug Davis 10 lat temu
rodzic
commit
bc149be69c
2 zmienionych plików z 23 dodań i 2 usunięć
  1. 21 0
      integration-cli/docker_cli_links_test.go
  2. 2 2
      links/links.go

+ 21 - 0
integration-cli/docker_cli_links_test.go

@@ -310,3 +310,24 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
 		c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip)
 		c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip)
 	}
 	}
 }
 }
+
+func (s *DockerSuite) TestLinksEnvs(c *check.C) {
+	runCmd := exec.Command(dockerBinary, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
+	out, _, _, err := runCommandWithStdoutStderr(runCmd)
+	if err != nil {
+		c.Fatalf("Run of first failed: %s\n%s", out, err)
+	}
+
+	runCmd = exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "busybox", "env")
+
+	out, stde, rc, err := runCommandWithStdoutStderr(runCmd)
+	if err != nil || rc != 0 {
+		c.Fatalf("run of 2nd failed: rc: %d, out: %s\n err: %s", rc, out, stde)
+	}
+
+	if !strings.Contains(out, "FIRST_ENV_e1=\n") ||
+		!strings.Contains(out, "FIRST_ENV_e2=v2") ||
+		!strings.Contains(out, "FIRST_ENV_e3=v3=v3") {
+		c.Fatalf("Incorrect output: %s", out)
+	}
+}

+ 2 - 2
links/links.go

@@ -107,8 +107,8 @@ func (l *Link) ToEnv() []string {
 
 
 	if l.ChildEnvironment != nil {
 	if l.ChildEnvironment != nil {
 		for _, v := range l.ChildEnvironment {
 		for _, v := range l.ChildEnvironment {
-			parts := strings.Split(v, "=")
-			if len(parts) != 2 {
+			parts := strings.SplitN(v, "=", 2)
+			if len(parts) < 2 {
 				continue
 				continue
 			}
 			}
 			// Ignore a few variables that are added during docker build (and not really relevant to linked containers)
 			// Ignore a few variables that are added during docker build (and not really relevant to linked containers)