mirror of https://github.com/docker/docker-py.git
Format environment variables to match docker-cli.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
cc399d22b4
commit
d9d84ce8d1
|
@ -821,6 +821,14 @@ def split_command(command):
|
||||||
return shlex.split(command)
|
return shlex.split(command)
|
||||||
|
|
||||||
|
|
||||||
|
def format_environment(environment):
|
||||||
|
def format_env(key, value):
|
||||||
|
if not value:
|
||||||
|
return key
|
||||||
|
return '{key}={value}'.format(key=key, value=value)
|
||||||
|
return [format_env(*var) for var in six.iteritems(environment)]
|
||||||
|
|
||||||
|
|
||||||
def create_container_config(
|
def create_container_config(
|
||||||
version, image, command, hostname=None, user=None, detach=False,
|
version, image, command, hostname=None, user=None, detach=False,
|
||||||
stdin_open=False, tty=False, mem_limit=None, ports=None, environment=None,
|
stdin_open=False, tty=False, mem_limit=None, ports=None, environment=None,
|
||||||
|
@ -836,10 +844,7 @@ def create_container_config(
|
||||||
entrypoint = split_command(entrypoint)
|
entrypoint = split_command(entrypoint)
|
||||||
|
|
||||||
if isinstance(environment, dict):
|
if isinstance(environment, dict):
|
||||||
environment = [
|
environment = format_environment(environment)
|
||||||
six.text_type('{0}={1}').format(k, v)
|
|
||||||
for k, v in six.iteritems(environment)
|
|
||||||
]
|
|
||||||
|
|
||||||
if labels is not None and compare_version('1.18', version) < 0:
|
if labels is not None and compare_version('1.18', version) < 0:
|
||||||
raise errors.InvalidVersion(
|
raise errors.InvalidVersion(
|
||||||
|
|
|
@ -370,6 +370,16 @@ class CreateContainerTest(helpers.BaseTestCase):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
self.client.create_host_config, pid_mode='40')
|
self.client.create_host_config, pid_mode='40')
|
||||||
|
|
||||||
|
def test_create_with_environment_variable_no_value(self):
|
||||||
|
container = self.client.create_container(
|
||||||
|
BUSYBOX,
|
||||||
|
['echo'],
|
||||||
|
environment={'Foo': None, 'Other': 'one'},
|
||||||
|
)
|
||||||
|
self.tmp_containers.append(container['Id'])
|
||||||
|
config = self.client.inspect_container(container['Id'])
|
||||||
|
assert sorted(config['Config']['Env']) == sorted(['Foo', 'Other=one'])
|
||||||
|
|
||||||
|
|
||||||
class VolumeBindTest(helpers.BaseTestCase):
|
class VolumeBindTest(helpers.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue