Make environment variables without a value the same as docker-cli.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
4b04280db8
commit
d451578152
7 changed files with 28 additions and 12 deletions
|
|
@ -827,7 +827,7 @@ def resolve_env_var(key, val):
|
|||
elif key in os.environ:
|
||||
return key, os.environ[key]
|
||||
else:
|
||||
return key, ''
|
||||
return key, None
|
||||
|
||||
|
||||
def env_vars_from_file(filename):
|
||||
|
|
|
|||
|
|
@ -134,7 +134,11 @@ class Container(object):
|
|||
|
||||
@property
|
||||
def environment(self):
|
||||
return dict(var.split("=", 1) for var in self.get('Config.Env') or [])
|
||||
def parse_env(var):
|
||||
if '=' in var:
|
||||
return var.split("=", 1)
|
||||
return var, None
|
||||
return dict(parse_env(var) for var in self.get('Config.Env') or [])
|
||||
|
||||
@property
|
||||
def exit_code(self):
|
||||
|
|
|
|||
|
|
@ -622,6 +622,8 @@ class Service(object):
|
|||
override_options,
|
||||
one_off=one_off)
|
||||
|
||||
container_options['environment'] = format_environment(
|
||||
container_options['environment'])
|
||||
return container_options
|
||||
|
||||
def _get_container_host_config(self, override_options, one_off=False):
|
||||
|
|
@ -1020,3 +1022,12 @@ def get_log_config(logging_dict):
|
|||
type=log_driver,
|
||||
config=log_options
|
||||
)
|
||||
|
||||
|
||||
# TODO: remove once fix is available in docker-py
|
||||
def format_environment(environment):
|
||||
def format_env(key, value):
|
||||
if value is None:
|
||||
return key
|
||||
return '{key}={value}'.format(key=key, value=value)
|
||||
return [format_env(*item) for item in environment.items()]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue