summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2015-12-08 12:47:31 -0800
committerJoffrey F <f.joffrey@gmail.com>2015-12-08 12:47:31 -0800
commit0f091747ece350d885f8d9829a488b63f3ff95c4 (patch)
treeb54e220fa5de5cde6f30aa59eb91edced3bc8ab3
parentbb1ab12f54d196930ff981e77497f00977c6db81 (diff)
parent31b1b53f7f803147056a5876e1789ca935d44c55 (diff)
downloaddocker-py-0f091747ece350d885f8d9829a488b63f3ff95c4.tar.gz
Merge pull request #868 from jstewmon/config-stop-signal
added stop_signal to create container config
-rw-r--r--docker/api/container.py5
-rw-r--r--docker/utils/utils.py8
-rw-r--r--docs/api.md1
-rw-r--r--tests/unit/container_test.py19
4 files changed, 30 insertions, 3 deletions
diff --git a/docker/api/container.py b/docker/api/container.py
index 00fa169..78cd216 100644
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -97,7 +97,8 @@ class ContainerApiMixin(object):
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None,
- mac_address=None, labels=None, volume_driver=None):
+ mac_address=None, labels=None, volume_driver=None,
+ stop_signal=None):
if isinstance(volumes, six.string_types):
volumes = [volumes, ]
@@ -112,7 +113,7 @@ class ContainerApiMixin(object):
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
memswap_limit, cpuset, host_config, mac_address, labels,
- volume_driver
+ volume_driver, stop_signal
)
return self.create_container_from_config(config, name)
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 3faf484..cd793d6 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -705,7 +705,7 @@ def create_container_config(
dns=None, volumes=None, volumes_from=None, network_disabled=False,
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None, mac_address=None,
- labels=None, volume_driver=None
+ labels=None, volume_driver=None, stop_signal=None
):
if isinstance(command, six.string_types):
command = split_command(command)
@@ -724,6 +724,11 @@ def create_container_config(
'labels were only introduced in API version 1.18'
)
+ if stop_signal is not None and compare_version('1.21', version) < 0:
+ raise errors.InvalidVersion(
+ 'stop_signal was only introduced in API version 1.21'
+ )
+
if compare_version('1.19', version) < 0:
if volume_driver is not None:
raise errors.InvalidVersion(
@@ -829,4 +834,5 @@ def create_container_config(
'MacAddress': mac_address,
'Labels': labels,
'VolumeDriver': volume_driver,
+ 'StopSignal': stop_signal
}
diff --git a/docs/api.md b/docs/api.md
index 6890427..31ec86a 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -224,6 +224,7 @@ from. Optionally a single string joining container id's with commas
* mac_address (str): The Mac Address to assign the container
* labels (dict or list): A dictionary of name-value labels (e.g. `{"label1": "value1", "label2": "value2"}`) or a list of names of labels to set with empty values (e.g. `["label1", "label2"]`)
* volume_driver (str): The name of a volume driver/plugin.
+* stop_signal (str): The stop signal to use to stop the container (e.g. `SIGINT`).
**Returns** (dict): A dictionary with an image 'Id' key and a 'Warnings' key.
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
index 2516c8f..e1dda3e 100644
--- a/tests/unit/container_test.py
+++ b/tests/unit/container_test.py
@@ -964,6 +964,25 @@ class CreateContainerTest(DockerClientTest):
DEFAULT_TIMEOUT_SECONDS
)
+ def test_create_container_with_stop_signal(self):
+ self.client.create_container('busybox', 'ls',
+ stop_signal='SIGINT')
+
+ args = fake_request.call_args
+ self.assertEqual(args[0][1],
+ url_prefix + 'containers/create')
+ self.assertEqual(json.loads(args[1]['data']),
+ json.loads('''
+ {"Tty": false, "Image": "busybox",
+ "Cmd": ["ls"], "AttachStdin": false,
+ "AttachStderr": true,
+ "AttachStdout": true, "OpenStdin": false,
+ "StdinOnce": false,
+ "NetworkDisabled": false,
+ "StopSignal": "SIGINT"}'''))
+ self.assertEqual(args[1]['headers'],
+ {'Content-Type': 'application/json'})
+
class ContainerTest(DockerClientTest):
def test_list_containers(self):