Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compose/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DOCKER_CONFIG_KEYS = [
'cap_add',
'cap_drop',
'cgroup_parent',
'command',
'cpu_shares',
'cpuset',
Expand Down
1 change: 1 addition & 0 deletions compose/config/fields_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
5 changes: 4 additions & 1 deletion compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
DOCKER_START_KEYS = [
'cap_add',
'cap_drop',
'cgroup_parent',
'devices',
'dns',
'dns_search',
Expand Down Expand Up @@ -677,6 +678,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),
Expand All @@ -698,7 +700,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):
Expand Down
6 changes: 6 additions & 0 deletions docs/yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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.
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ def test_create_container_no_build(self):
service.create_container(do_build=False)
self.assertFalse(self.mock_client.build.called)

def test_create_container_no_build_cgroup_parent(self):
service = Service('foo', client=self.mock_client, build='.')
service.image = lambda: {'Id': 'abc123'}

service.create_container(do_build=False, cgroup_parent='test')
self.assertFalse(self.mock_client.build.called)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this test is testing that our cgroup_parent option was passed in correctly. I think this is the the wrong place to write the test for the option.

Maybe something along the lines to this test, https://github.com/docker/compose/blob/master/tests/unit/service_test.py#L111
where we can see that the cgroup_parent, if specified, is sent to create_host_config.


def test_create_container_no_build_but_needs_build(self):
service = Service('foo', client=self.mock_client, build='.')
service.image = lambda *args, **kwargs: mock_get_image([])
Expand Down