1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #12783 from duglin/Issue12763-LinkedEnvs

A fix for = in env values in linked containers
This commit is contained in:
Brian Goff 2015-04-27 10:50:14 -04:00
commit 8dc07af52f
2 changed files with 23 additions and 2 deletions

View file

@ -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)
}
}

View file

@ -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, "=") parts := strings.SplitN(v, "=", 2)
if len(parts) != 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)