diff --git a/container.go b/container.go index 9fff926e40..8b7f98955f 100644 --- a/container.go +++ b/container.go @@ -226,6 +226,18 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, } } + envs := []string{} + + for _, env := range flEnv { + arr := strings.Split(env, "=") + if len(arr) > 1 { + envs = append(envs, env) + } else { + v := os.Getenv(env) + envs = append(envs, env+"="+v) + } + } + var binds []string // add any bind targets to the list of container volumes @@ -298,7 +310,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, AttachStdin: flAttach.Get("stdin"), AttachStdout: flAttach.Get("stdout"), AttachStderr: flAttach.Get("stderr"), - Env: flEnv, + Env: envs, Cmd: runCmd, Dns: flDns, Image: image, diff --git a/container_test.go b/container_test.go index 262d6fcb1d..90ca6defea 100644 --- a/container_test.go +++ b/container_test.go @@ -973,14 +973,14 @@ func TestTty(t *testing.T) { } func TestEnv(t *testing.T) { + os.Setenv("TRUE", "false") runtime := mkRuntime(t) defer nuke(runtime) - container, _, err := runtime.Create(&Config{ - Image: GetTestImage(runtime).ID, - Cmd: []string{"env"}, - }, - "", - ) + config, _, _, err := ParseRun([]string{"-e=FALSE=true", "-e=TRUE", GetTestImage(runtime).ID, "env"}, nil) + if err != nil { + t.Fatal(err) + } + container, _, err := runtime.Create(config, "") if err != nil { t.Fatal(err) } @@ -1010,6 +1010,8 @@ func TestEnv(t *testing.T) { "HOME=/", "container=lxc", "HOSTNAME=" + container.ShortID(), + "FALSE=true", + "TRUE=false", } sort.Strings(goodEnv) if len(goodEnv) != len(actualEnv) {