Merge pull request #1415 from docker/autoremove_support

Add support for auto_remove in HostConfig
This commit is contained in:
Joffrey F 2017-01-26 14:24:23 -08:00 committed by GitHub
commit 64519a2b20
4 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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}'

View File

@ -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):