diff options
author | Joffrey F <joffrey@docker.com> | 2017-01-25 16:45:59 -0800 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2017-01-25 16:45:59 -0800 |
commit | 848b7aa6a4721a58831d3d9c611cc261217a1b4b (patch) | |
tree | 1383d6661613e945769ad6f79f2b42fcf35a5a56 | |
parent | 4ff77dc1c910e07117c925cf0f9784529f3bd8d5 (diff) | |
download | docker-py-autoremove_support.tar.gz |
Add support for auto_remove in HostConfigautoremove_support
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/api/container.py | 2 | ||||
-rw-r--r-- | docker/models/containers.py | 2 | ||||
-rw-r--r-- | docker/types/containers.py | 7 | ||||
-rw-r--r-- | tests/integration/api_container_test.py | 12 |
4 files changed, 22 insertions, 1 deletions
diff --git a/docker/api/container.py b/docker/api/container.py index efcae9b..482b7b6 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -457,6 +457,8 @@ class ContainerApiMixin(object): :py:meth:`create_container`. Args: + auto_remove (bool): enable auto-removal of the container on daemon + side when the container's process exits. binds (dict): Volumes to bind. See :py:meth:`create_container` for more information. blkio_weight_device: Block IO weight (relative device weight) in diff --git a/docker/models/containers.py b/docker/models/containers.py index 259828a..6acc4bb 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -446,6 +446,8 @@ class ContainerCollection(Collection): Args: image (str): The image to run. command (str or list): The command to run in the container. + auto_remove (bool): enable auto-removal of the container on daemon + side when the container's process exits. blkio_weight_device: Block IO weight (relative device weight) in the form of: ``[{"Path": "device_path", "Weight": weight}]``. blkio_weight: Block IO weight (relative weight), accepts a weight diff --git a/docker/types/containers.py b/docker/types/containers.py index 8fdecb3..7e7d9ea 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -117,7 +117,7 @@ class HostConfig(dict): oom_kill_disable=False, shm_size=None, sysctls=None, tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None, cpuset_cpus=None, userns_mode=None, pids_limit=None, - isolation=None): + isolation=None, auto_remove=False): if mem_limit is not None: self['Memory'] = parse_bytes(mem_limit) @@ -407,6 +407,11 @@ class HostConfig(dict): raise host_config_version_error('isolation', '1.24') self['Isolation'] = isolation + if auto_remove: + if version_lt(version, '1.25'): + raise host_config_version_error('auto_remove', '1.25') + self['AutoRemove'] = auto_remove + def host_config_type_error(param, param_value, expected): error_msg = 'Invalid type for {0} param: expected {1} but found {2}' diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index bebadb7..fc748f1 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -401,6 +401,18 @@ class CreateContainerTest(BaseAPIIntegrationTest): config = self.client.inspect_container(container) assert config['HostConfig']['Isolation'] == 'default' + @requires_api_version('1.25') + def test_create_with_auto_remove(self): + host_config = self.client.create_host_config( + auto_remove=True + ) + container = self.client.create_container( + BUSYBOX, ['echo', 'test'], host_config=host_config + ) + self.tmp_containers.append(container['Id']) + config = self.client.inspect_container(container) + assert config['HostConfig']['AutoRemove'] is True + class VolumeBindTest(BaseAPIIntegrationTest): def setUp(self): |