diff --git a/compose/config/config.py b/compose/config/config.py index 9e9cb857fbf..1a995fa8e1c 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -21,6 +21,7 @@ DOCKER_CONFIG_KEYS = [ 'cap_add', 'cap_drop', + 'cgroup_parent', 'command', 'cpu_shares', 'cpuset', diff --git a/compose/config/fields_schema.json b/compose/config/fields_schema.json index 6fce299cbb1..da67774fdfb 100644 --- a/compose/config/fields_schema.json +++ b/compose/config/fields_schema.json @@ -17,6 +17,7 @@ "build": {"type": "string"}, "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "cgroup_parent": {"type": "string"}, "command": { "oneOf": [ {"type": "string"}, diff --git a/compose/service.py b/compose/service.py index 044b34ad5e7..0d89afc02d0 100644 --- a/compose/service.py +++ b/compose/service.py @@ -41,6 +41,7 @@ DOCKER_START_KEYS = [ 'cap_add', 'cap_drop', + 'cgroup_parent', 'devices', 'dns', 'dns_search', @@ -675,6 +676,7 @@ def _get_container_host_config(self, override_options, one_off=False): read_only = options.get('read_only', None) devices = options.get('devices', None) + cgroup_parent = options.get('cgroup_parent', None) return self.client.create_host_config( links=self._get_links(link_to_self=one_off), @@ -696,7 +698,8 @@ def _get_container_host_config(self, override_options, one_off=False): read_only=read_only, pid_mode=pid, security_opt=security_opt, - ipc_mode=options.get('ipc') + ipc_mode=options.get('ipc'), + cgroup_parent=cgroup_parent ) def build(self, no_cache=False, pull=False): diff --git a/docs/compose-file.md b/docs/compose-file.md index 725130f7897..67322335a78 100644 --- a/docs/compose-file.md +++ b/docs/compose-file.md @@ -56,6 +56,12 @@ Override the default command. command: bundle exec thin -p 3000 +### cgroup_parent + +Specify an optional parent cgroup for the container. + + cgroup_parent: m-executor-abcd + ### container_name Specify a custom container name, rather than a generated default name. diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index 19d25e2ed54..84ede755312 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -146,6 +146,18 @@ def test_memory_swap_limit(self): 2000000000 ) + def test_cgroup_parent(self): + self.mock_client.create_host_config.return_value = {} + + service = Service(name='foo', image='foo', hostname='name', client=self.mock_client, cgroup_parent='test') + service._get_container_create_options({'some': 'overrides'}, 1) + + self.assertTrue(self.mock_client.create_host_config.called) + self.assertEqual( + self.mock_client.create_host_config.call_args[1]['cgroup_parent'], + 'test' + ) + def test_log_opt(self): self.mock_client.create_host_config.return_value = {}