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

Support cgroupns option in containers.run/containers.create #2930

Merged
merged 1 commit into from
Jul 29, 2022
Merged
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
6 changes: 6 additions & 0 deletions docker/models/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ 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.
cgroupns (str): Override the default cgroup namespace mode for the
container. One of:
- ``private`` the container runs in its own private cgroup
namespace.
- ``host`` use the host system's cgroup namespace.
cpu_count (int): Number of usable CPUs (Windows only).
cpu_percent (int): Usable percentage of the available CPUs
(Windows only).
Expand Down Expand Up @@ -1001,6 +1006,7 @@ def prune(self, filters=None):
'cap_add',
'cap_drop',
'cgroup_parent',
'cgroupns',
'cpu_count',
'cpu_percent',
'cpu_period',
Expand Down
6 changes: 5 additions & 1 deletion docker/types/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def __init__(self, version, binds=None, port_bindings=None,
volume_driver=None, cpu_count=None, cpu_percent=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):
device_cgroup_rules=None, device_requests=None,
cgroupns=None):

if mem_limit is not None:
self['Memory'] = parse_bytes(mem_limit)
Expand Down Expand Up @@ -646,6 +647,9 @@ def __init__(self, version, binds=None, port_bindings=None,
req = DeviceRequest(**req)
self['DeviceRequests'].append(req)

if cgroupns:
self['CgroupnsMode'] = cgroupns


def host_config_type_error(param, param_value, expected):
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_create_container_args(self):
cap_add=['foo'],
cap_drop=['bar'],
cgroup_parent='foobar',
cgroupns='host',
cpu_period=1,
cpu_quota=2,
cpu_shares=5,
Expand Down Expand Up @@ -134,6 +135,7 @@ def test_create_container_args(self):
'BlkioWeight': 2,
'CapAdd': ['foo'],
'CapDrop': ['bar'],
'CgroupnsMode': 'host',
'CgroupParent': 'foobar',
'CpuPeriod': 1,
'CpuQuota': 2,
Expand Down