diff --git a/docker/client.py b/docker/client.py index e4712c23c3..f79ec7bb09 100644 --- a/docker/client.py +++ b/docker/client.py @@ -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, @@ -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, @@ -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) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index a714c97c4b..98d17ef50a 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -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 diff --git a/docker/version.py b/docker/version.py index bc778b93b8..d0aad76af5 100644 --- a/docker/version.py +++ b/docker/version.py @@ -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(".")]) diff --git a/tests/integration_test.py b/tests/integration_test.py index 226ea34c2c..59919dabeb 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -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) @@ -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) @@ -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']) @@ -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']) @@ -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'] @@ -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) @@ -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'] @@ -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'] @@ -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) @@ -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'] diff --git a/tests/utils_test.py b/tests/utils_test.py index 1c8729ca00..fd9d7f3fc2 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -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):