Skip to content

Commit cf688d2

Browse files
committed
feat: add cgroup to host config--according to api docs (closes#2340)
Signed-off-by: Khushiyant <[email protected]> fix: unexpected keyword argument Signed-off-by: Khushiyant <[email protected]>
1 parent db7f8b8 commit cf688d2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docker/models/containers.py

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
570570
``["SYS_ADMIN", "MKNOD"]``.
571571
cap_drop (list of str): Drop kernel capabilities.
572572
cgroup_parent (str): Override the default parent cgroup.
573+
cgroup (str): Cgroup to use for the container.
573574
cgroupns (str): Override the default cgroup namespace mode for the
574575
container. One of:
575576
- ``private`` the container runs in its own private cgroup

docker/types/containers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def __init__(self, version, binds=None, port_bindings=None,
284284
nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None,
285285
cpu_rt_period=None, cpu_rt_runtime=None,
286286
device_cgroup_rules=None, device_requests=None,
287-
cgroupns=None):
287+
cgroupns=None, cgroup=None):
288288

289289
if mem_limit is not None:
290290
self['Memory'] = parse_bytes(mem_limit)
@@ -424,6 +424,10 @@ def __init__(self, version, binds=None, port_bindings=None,
424424
if cgroup_parent is not None:
425425
self['CgroupParent'] = cgroup_parent
426426

427+
if cgroup is not None:
428+
if isinstance(cgroup, str):
429+
self['Cgroup'] = cgroup
430+
427431
if ulimits is not None:
428432
if not isinstance(ulimits, list):
429433
raise host_config_type_error('ulimits', ulimits, 'list')

tests/unit/api_container_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,20 @@ def test_create_container_with_cgroup_parent(self):
306306
assert 'CgroupParent' in data['HostConfig']
307307
assert data['HostConfig']['CgroupParent'] == 'test'
308308

309+
def test_create_container_with_cgroup(self):
310+
self.client.create_container(
311+
'busybox', 'ls', host_config=self.client.create_host_config(
312+
cgroup='host'
313+
)
314+
)
315+
316+
args = fake_request.call_args
317+
assert args[0][1] == url_prefix + 'containers/create'
318+
data = json.loads(args[1]['data'])
319+
assert 'HostConfig' in data
320+
assert 'Cgroup' in data['HostConfig']
321+
assert data['HostConfig']['Cgroup'] == 'host'
322+
309323
def test_create_container_with_working_dir(self):
310324
self.client.create_container('busybox', 'ls',
311325
working_dir='/root')

0 commit comments

Comments
 (0)