diff --git a/docker/api/container.py b/docker/api/container.py index 00fa1696..78cd216c 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 3faf484f..cd793d65 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 68904276..31ec86a8 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 2516c8f0..e1dda3e3 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):