Skip to content

Commit d69de54

Browse files
authored
api: add cgroupns option to container create (#2930)
Signed-off-by: David Otto <[email protected]>
1 parent 1a4cacd commit d69de54

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docker/models/containers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ def run(self, image, command=None, stdout=True, stderr=False,
553553
``["SYS_ADMIN", "MKNOD"]``.
554554
cap_drop (list of str): Drop kernel capabilities.
555555
cgroup_parent (str): Override the default parent cgroup.
556+
cgroupns (str): Override the default cgroup namespace mode for the
557+
container. One of:
558+
- ``private`` the container runs in its own private cgroup
559+
namespace.
560+
- ``host`` use the host system's cgroup namespace.
556561
cpu_count (int): Number of usable CPUs (Windows only).
557562
cpu_percent (int): Usable percentage of the available CPUs
558563
(Windows only).
@@ -1002,6 +1007,7 @@ def prune(self, filters=None):
10021007
'cap_add',
10031008
'cap_drop',
10041009
'cgroup_parent',
1010+
'cgroupns',
10051011
'cpu_count',
10061012
'cpu_percent',
10071013
'cpu_period',

docker/types/containers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def __init__(self, version, binds=None, port_bindings=None,
272272
volume_driver=None, cpu_count=None, cpu_percent=None,
273273
nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None,
274274
cpu_rt_period=None, cpu_rt_runtime=None,
275-
device_cgroup_rules=None, device_requests=None):
275+
device_cgroup_rules=None, device_requests=None,
276+
cgroupns=None):
276277

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

650+
if cgroupns:
651+
self['CgroupnsMode'] = cgroupns
652+
649653

650654
def host_config_type_error(param, param_value, expected):
651655
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'

tests/unit/models_containers_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_create_container_args(self):
3939
cap_add=['foo'],
4040
cap_drop=['bar'],
4141
cgroup_parent='foobar',
42+
cgroupns='host',
4243
cpu_period=1,
4344
cpu_quota=2,
4445
cpu_shares=5,
@@ -135,6 +136,7 @@ def test_create_container_args(self):
135136
'BlkioWeight': 2,
136137
'CapAdd': ['foo'],
137138
'CapDrop': ['bar'],
139+
'CgroupnsMode': 'host',
138140
'CgroupParent': 'foobar',
139141
'CpuPeriod': 1,
140142
'CpuQuota': 2,

0 commit comments

Comments
 (0)