diff --git a/docker/client.py b/docker/client.py index 771feb3c..96b3cdcd 100644 --- a/docker/client.py +++ b/docker/client.py @@ -470,7 +470,8 @@ class Client(requests.Session): return self._result(self.get(self._url("/images/search"), params={'term': term}), True) - def start(self, container, binds=None, port_bindings=None, lxc_conf=None): + def start(self, container, binds=None, port_bindings=None, lxc_conf=None, + publish_all_ports=False): if isinstance(container, dict): container = container.get('Id') @@ -492,6 +493,8 @@ class Client(requests.Session): if port_bindings: start_config['PortBindings'] = port_bindings + start_config['PublishAllPorts'] = publish_all_ports + url = self._url("/containers/{0}/start".format(container)) res = self._post_json(url, start_config) self._raise_for_status(res) diff --git a/tests/test.py b/tests/test.py index dce465c1..985fd85e 100644 --- a/tests/test.py +++ b/tests/test.py @@ -231,7 +231,7 @@ class DockerClientTest(unittest.TestCase): fake_request.assert_called_with( 'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start', - '{}', + '{"PublishAllPorts": false}', headers={'Content-Type': 'application/json'} ) @@ -248,7 +248,8 @@ class DockerClientTest(unittest.TestCase): 'containers/3cc2351ab11b/start') self.assertEqual( json.loads(args[0][1]), - {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]} + {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}], + "PublishAllPorts": False} ) self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'}) @@ -266,7 +267,8 @@ class DockerClientTest(unittest.TestCase): 'containers/3cc2351ab11b/start') self.assertEqual( json.loads(args[0][1]), - {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]} + {"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}], + "PublishAllPorts": False} ) self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'}) @@ -282,7 +284,7 @@ class DockerClientTest(unittest.TestCase): fake_request.assert_called_with( 'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start', - '{"Binds": ["/tmp:/mnt"]}', + '{"Binds": ["/tmp:/mnt"], "PublishAllPorts": false}', headers={'Content-Type': 'application/json'} ) @@ -293,7 +295,8 @@ class DockerClientTest(unittest.TestCase): self.fail('Command should not raise exception: {0}'.format(e)) fake_request.assert_called_with( 'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start', - '{}', headers={'Content-Type': 'application/json'} + '{"PublishAllPorts": false}', + headers={'Content-Type': 'application/json'} ) def test_wait(self):