Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Cgroup to HostConfig Object in ContainerCreate #3315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 docker/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
``["SYS_ADMIN", "MKNOD"]``.
cap_drop (list of str): Drop kernel capabilities.
cgroup_parent (str): Override the default parent cgroup.
cgroup (str): Cgroup to use for the container.
cgroupns (str): Override the default cgroup namespace mode for the
container. One of:
- ``private`` the container runs in its own private cgroup
Expand Down
6 changes: 5 additions & 1 deletion docker/types/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def __init__(self, version, binds=None, port_bindings=None,
nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None,
cpu_rt_period=None, cpu_rt_runtime=None,
device_cgroup_rules=None, device_requests=None,
cgroupns=None):
cgroupns=None, cgroup=None):

if mem_limit is not None:
self['Memory'] = parse_bytes(mem_limit)
Expand Down Expand Up @@ -424,6 +424,10 @@ def __init__(self, version, binds=None, port_bindings=None,
if cgroup_parent is not None:
self['CgroupParent'] = cgroup_parent

if cgroup is not None:
if isinstance(cgroup, str):
self['Cgroup'] = cgroup

if ulimits is not None:
if not isinstance(ulimits, list):
raise host_config_type_error('ulimits', ulimits, 'list')
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ def test_create_container_with_cgroup_parent(self):
assert 'CgroupParent' in data['HostConfig']
assert data['HostConfig']['CgroupParent'] == 'test'

def test_create_container_with_cgroup(self):
self.client.create_container(
'busybox', 'ls', host_config=self.client.create_host_config(
cgroup='host'
)
)

args = fake_request.call_args
assert args[0][1] == url_prefix + 'containers/create'
data = json.loads(args[1]['data'])
assert 'HostConfig' in data
assert 'Cgroup' in data['HostConfig']
assert data['HostConfig']['Cgroup'] == 'host'

def test_create_container_with_working_dir(self):
self.client.create_container('busybox', 'ls',
working_dir='/root')
Expand Down