Docker run -e FOO should erase FOO if FOO isn't set in client env

See #10141 for more info, but the main point of this is to make sure
that if you do "docker run -e FOO ..." that FOO from the current env
is passed into the container.  This means that if there's a value, its
set.  But it also means that if FOO isn't set then it should be unset in
the container too - even if it has to remove it from the env.  So,
   unset HOSTNAME
   docker run -e HOSTNAME busybox env
should _NOT_ show HOSTNAME in the list at all

Closes #10141

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-01-16 12:57:08 -08:00 committed by Vincent Demeester
parent 4440f5aa3f
commit 67735d2a16
1 changed files with 4 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/utils"
) )
var ( var (
@ -168,6 +169,9 @@ func ValidateEnv(val string) (string, error) {
if len(arr) > 1 { if len(arr) > 1 {
return val, nil return val, nil
} }
if !utils.DoesEnvExist(val) {
return val, nil
}
return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil
} }