Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def search(self, term):

@check_resource
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
publish_all_ports=False, links=None, privileged=False,
publish_all_ports=None, links=None, privileged=None,
dns=None, dns_search=None, volumes_from=None, network_mode=None,
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
Expand Down Expand Up @@ -775,7 +775,7 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
'ulimits is only supported for API version >= 1.18'
)

start_config = utils.create_host_config(
start_config_kwargs = dict(
binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
publish_all_ports=publish_all_ports, links=links, dns=dns,
privileged=privileged, dns_search=dns_search, cap_add=cap_add,
Expand All @@ -784,16 +784,18 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits
)
start_config = None

if any(v is not None for v in start_config_kwargs.values()):
if utils.compare_version('1.15', self._version) > 0:
warnings.warn(
'Passing host config parameters in start() is deprecated. '
'Please use host_config in create_container instead!',
DeprecationWarning
)
start_config = utils.create_host_config(**start_config_kwargs)

url = self._url("/containers/{0}/start".format(container))
if not start_config:
start_config = None
elif utils.compare_version('1.15', self._version) > 0:
warnings.warn(
'Passing host config parameters in start() is deprecated. '
'Please use host_config in create_container instead!',
DeprecationWarning
)
res = self._post_json(url, data=start_config)
self._raise_for_status(res)

Expand Down
2 changes: 2 additions & 0 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ def create_host_config(

if network_mode:
host_config['NetworkMode'] = network_mode
elif network_mode is None:
host_config['NetworkMode'] = 'default'

if restart_policy:
host_config['RestartPolicy'] = restart_policy
Expand Down
2 changes: 1 addition & 1 deletion docker/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "1.3.1"
version = "1.4.0-dev"
version_info = tuple([int(d) for d in version.split("-")[0].split(".")])
34 changes: 24 additions & 10 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def runTest(self):
container = self.client.create_container(
'busybox',
['ls', mount_dest], volumes={mount_dest: {}},
host_config=create_host_config(binds=binds)
host_config=create_host_config(
binds=binds, network_mode='none'
)
)
container_id = container['Id']
self.client.start(container_id)
Expand Down Expand Up @@ -221,7 +223,9 @@ def runTest(self):
container = self.client.create_container(
'busybox',
['ls', mount_dest], volumes={mount_dest: {}},
host_config=create_host_config(binds=binds)
host_config=create_host_config(
binds=binds, network_mode='none'
)
)
container_id = container['Id']
self.client.start(container_id)
Expand Down Expand Up @@ -273,7 +277,9 @@ class TestCreateContainerReadOnlyFs(BaseTestCase):
def runTest(self):
ctnr = self.client.create_container(
'busybox', ['mkdir', '/shrine'],
host_config=create_host_config(read_only=True)
host_config=create_host_config(
read_only=True, network_mode='none'
)
)
self.assertIn('Id', ctnr)
self.tmp_containers.append(ctnr['Id'])
Expand Down Expand Up @@ -347,7 +353,9 @@ def runTest(self):
class TestCreateContainerPrivileged(BaseTestCase):
def runTest(self):
res = self.client.create_container(
'busybox', 'true', host_config=create_host_config(privileged=True)
'busybox', 'true', host_config=create_host_config(
privileged=True, network_mode='none'
)
)
self.assertIn('Id', res)
self.tmp_containers.append(res['Id'])
Expand Down Expand Up @@ -591,7 +599,9 @@ def runTest(self):

container = self.client.create_container(
'busybox', ['sleep', '60'], ports=list(port_bindings.keys()),
host_config=create_host_config(port_bindings=port_bindings)
host_config=create_host_config(
port_bindings=port_bindings, network_mode='bridge'
)
)
id = container['Id']

Expand Down Expand Up @@ -717,7 +727,9 @@ def runTest(self):
)
res2 = self.client.create_container(
'busybox', 'cat', detach=True, stdin_open=True,
host_config=create_host_config(volumes_from=vol_names)
host_config=create_host_config(
volumes_from=vol_names, network_mode='none'
)
)
container3_id = res2['Id']
self.tmp_containers.append(container3_id)
Expand Down Expand Up @@ -760,7 +772,8 @@ def runTest(self):

res2 = self.client.create_container(
'busybox', 'env', host_config=create_host_config(
links={link_path1: link_alias1, link_path2: link_alias2}
links={link_path1: link_alias1, link_path2: link_alias2},
network_mode='none'
)
)
container3_id = res2['Id']
Expand All @@ -781,7 +794,8 @@ class TestRestartingContainer(BaseTestCase):
def runTest(self):
container = self.client.create_container(
'busybox', ['sleep', '2'], host_config=create_host_config(
restart_policy={"Name": "always", "MaximumRetryCount": 0}
restart_policy={"Name": "always", "MaximumRetryCount": 0},
network_mode='none'
)
)
id = container['Id']
Expand Down Expand Up @@ -910,7 +924,7 @@ class TestCreateContainerWithHostPidMode(BaseTestCase):
def runTest(self):
ctnr = self.client.create_container(
'busybox', 'true', host_config=create_host_config(
pid_mode='host'
pid_mode='host', network_mode='none'
)
)
self.assertIn('Id', ctnr)
Expand Down Expand Up @@ -945,7 +959,7 @@ def runTest(self):

container2 = self.client.create_container(
'busybox', 'cat', host_config=create_host_config(
links={link_path: link_alias}
links={link_path: link_alias}, network_mode='none'
)
)
container2_id = container2['Id']
Expand Down
2 changes: 1 addition & 1 deletion tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_convert_filters(self):
self.assertEqual(convert_filters(filters), expected)

def test_create_empty_host_config(self):
empty_config = create_host_config()
empty_config = create_host_config(network_mode='')
self.assertEqual(empty_config, {})

def test_create_host_config_dict_ulimit(self):
Expand Down