diff options
-rw-r--r-- | docker/client.py | 32 | ||||
-rw-r--r-- | docker/utils/utils.py | 3 | ||||
-rw-r--r-- | docker/version.py | 4 | ||||
-rw-r--r-- | docs/api.md | 4 | ||||
-rw-r--r-- | docs/change_log.md | 33 | ||||
-rw-r--r-- | docs/volumes.md | 13 | ||||
-rw-r--r-- | tests/test.py | 30 |
7 files changed, 104 insertions, 15 deletions
diff --git a/docker/client.py b/docker/client.py index 0851865..c73e560 100644 --- a/docker/client.py +++ b/docker/client.py @@ -307,7 +307,8 @@ class Client(requests.Session): def build(self, path=None, tag=None, quiet=False, fileobj=None, nocache=False, rm=False, stream=False, timeout=None, custom_context=False, encoding=None, pull=True, - forcerm=False, dockerfile=None, container_limits=None): + forcerm=False, dockerfile=None, container_limits=None, + decode=False): remote = context = headers = None container_limits = container_limits or {} if path is None and fileobj is None: @@ -398,7 +399,7 @@ class Client(requests.Session): context.close() if stream: - return self._stream_helper(response) + return self._stream_helper(response, decode=decode) else: output = self._result(response) srch = r'Successfully built ([0-9a-f]+)' @@ -911,13 +912,17 @@ class Client(requests.Session): else: headers['X-Registry-Auth'] = auth.encode_header(auth_config) - response = self._post(self._url('/images/create'), params=params, - headers=headers, stream=stream, timeout=None) + response = self._post( + self._url('/images/create'), params=params, headers=headers, + stream=stream, timeout=None + ) + + self._raise_for_status(response) if stream: return self._stream_helper(response) - else: - return self._result(response) + + return self._result(response) def push(self, repository, tag=None, stream=False, insecure_registry=False): @@ -945,13 +950,16 @@ class Client(requests.Session): if authcfg: headers['X-Registry-Auth'] = auth.encode_header(authcfg) - response = self._post_json(u, None, headers=headers, - stream=stream, params=params) - else: - response = self._post_json(u, None, stream=stream, params=params) + response = self._post_json( + u, None, headers=headers, stream=stream, params=params + ) + + self._raise_for_status(response) + + if stream: + return self._stream_helper(response) - return stream and self._stream_helper(response) \ - or self._result(response) + return self._result(response) @check_resource def remove_container(self, container, v=False, link=False, force=False): diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 7ab5592..84acca3 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -174,6 +174,9 @@ def convert_port_bindings(port_bindings): def convert_volume_binds(binds): + if isinstance(binds, list): + return binds + result = [] for k, v in binds.items(): if isinstance(v, dict): diff --git a/docker/version.py b/docker/version.py index 7ff5b2a..88859a6 100644 --- a/docker/version.py +++ b/docker/version.py @@ -1,2 +1,2 @@ -version = "1.2.3-dev" -version_info = tuple([int(d) for d in version.replace("-dev", "").split(".")]) +version = "1.3.0-dev" +version_info = tuple([int(d) for d in version.split("-")[0].split(".")]) diff --git a/docs/api.md b/docs/api.md index 3b3a144..4b64147 100644 --- a/docs/api.md +++ b/docs/api.md @@ -71,8 +71,10 @@ correct value (e.g `gzip`). - memswap (int): Total memory (memory + swap), -1 to disable swap - cpushares (int): CPU shares (relative weight) - cpusetcpus (str): CPUs in which to allow exection, e.g., `"0-3"`, `"0,1"` +* decode (bool): If set to `True`, the returned stream will be decoded into + dicts on the fly. Default `False`. -**Returns** (generator): A generator of the build output +**Returns** (generator): A generator for the build output ```python >>> from io import BytesIO diff --git a/docs/change_log.md b/docs/change_log.md index 5bbbc93..837655f 100644 --- a/docs/change_log.md +++ b/docs/change_log.md @@ -1,6 +1,39 @@ Change Log ========== +1.2.3 +----- + +[List of PRs / issues for this release](https://github.com/docker/docker-py/issues?q=milestone%3A1.2.3+is%3Aclosed) + +### Deprecation warning + +* Passing host config in the `Client.start` method is now deprecated. Please use the + `host_config` in `Client.create_container` instead. + +### Features + +* Added support for `privileged` param in `Client.exec_create` + (only available in API >= 1.19) + +### Bugfixes + +* Fixed a bug where the `read_only` param in host_config wasn't handled + properly. +* Fixed a bug in `Client.execute` (this method is still deprecated). +* The `cpuset` param in `Client.create_container` is also passed as + the `CpusetCpus` param (`Cpuset` deprecated in recent versions of the API) +* Fixed an issue with integration tests being run inside a container + (`make integration-test`) +* Fixed a bug where an empty string would be considered a valid container ID + or image ID. +* Fixed a bug in `Client.insert` + + +### Documentation + +* Various fixes + 1.2.2 ----- diff --git a/docs/volumes.md b/docs/volumes.md index de28214..db42155 100644 --- a/docs/volumes.md +++ b/docs/volumes.md @@ -19,3 +19,16 @@ container_id = c.create_container( }) ) ``` + +You can alternatively specify binds as a list. This code is equivalent to the +example above: + +```python +container_id = c.create_container( + 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'], + host_config=docker.utils.create_host_config(binds=[ + '/home/user1/:/mnt/vol2', + '/var/www:/mnt/vol1:ro', + ]) +) +``` diff --git a/tests/test.py b/tests/test.py index 42b8135..f5815f0 100644 --- a/tests/test.py +++ b/tests/test.py @@ -808,6 +808,36 @@ class DockerClientTest(Cleanup, base.BaseTestCase): DEFAULT_TIMEOUT_SECONDS ) + def test_create_container_with_binds_list(self): + try: + self.client.create_container( + 'busybox', 'true', host_config=create_host_config( + binds=[ + "/tmp:/mnt/1:ro", + "/tmp:/mnt/2", + ], + ) + ) + except Exception as e: + self.fail('Command should not raise exception: {0}'.format(e)) + + args = fake_request.call_args + self.assertEqual(args[0][0], url_prefix + + 'containers/create') + expected_payload = self.base_create_payload() + expected_payload['HostConfig'] = create_host_config() + expected_payload['HostConfig']['Binds'] = [ + "/tmp:/mnt/1:ro", + "/tmp:/mnt/2", + ] + self.assertEqual(json.loads(args[1]['data']), expected_payload) + self.assertEqual(args[1]['headers'], + {'Content-Type': 'application/json'}) + self.assertEqual( + args[1]['timeout'], + DEFAULT_TIMEOUT_SECONDS + ) + def test_create_container_with_port_binds(self): self.maxDiff = None try: |