Skip to content

Commit 7b7e07e

Browse files
committed
Merge branch 'srikalyan-master'
2 parents 3709c70 + 797f1ed commit 7b7e07e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docker/utils/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
621621
device_write_iops=None, oom_kill_disable=False,
622622
shm_size=None, sysctls=None, version=None, tmpfs=None,
623623
oom_score_adj=None, dns_opt=None, cpu_shares=None,
624-
cpuset_cpus=None):
624+
cpuset_cpus=None, userns_mode=None):
625625

626626
host_config = {}
627627

@@ -882,6 +882,14 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
882882
raise host_config_version_error('tmpfs', '1.22')
883883
host_config["Tmpfs"] = convert_tmpfs_mounts(tmpfs)
884884

885+
if userns_mode:
886+
if version_lt(version, '1.23'):
887+
raise host_config_version_error('userns_mode', '1.23')
888+
889+
if userns_mode != "host":
890+
raise host_config_value_error("userns_mode", userns_mode)
891+
host_config['UsernsMode'] = userns_mode
892+
885893
return host_config
886894

887895

docs/hostconfig.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ for example:
123123
container process will run as.
124124
* devices (list): Host device bindings. See [host devices](host-devices.md)
125125
for more information.
126-
* tmpfs: Temporary filesystems to mouunt. See [Using tmpfs](tmpfs.md) for more
126+
* tmpfs: Temporary filesystems to mount. See [Using tmpfs](tmpfs.md) for more
127127
information.
128128
* sysctls (dict): Kernel parameters to set in the container.
129+
* userns_mode (str): Sets the user namespace mode for the container when user
130+
namespace remapping option is enabled. Supported values are: `host`
129131

130132
**Returns** (dict) HostConfig dictionary
131133

tests/unit/utils_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ def test_create_host_config_with_oom_kill_disable(self):
131131
InvalidVersion, lambda: create_host_config(version='1.18.3',
132132
oom_kill_disable=True))
133133

134+
def test_create_host_config_with_userns_mode(self):
135+
config = create_host_config(version='1.23', userns_mode='host')
136+
self.assertEqual(config.get('UsernsMode'), 'host')
137+
self.assertRaises(
138+
InvalidVersion, lambda: create_host_config(version='1.22',
139+
userns_mode='host'))
140+
self.assertRaises(
141+
ValueError, lambda: create_host_config(version='1.23',
142+
userns_mode='host12'))
143+
134144
def test_create_host_config_with_oom_score_adj(self):
135145
config = create_host_config(version='1.22', oom_score_adj=100)
136146
self.assertEqual(config.get('OomScoreAdj'), 100)
@@ -656,7 +666,6 @@ def test_create_ipam_config(self):
656666

657667

658668
class SplitCommandTest(base.BaseTestCase):
659-
660669
def test_split_command_with_unicode(self):
661670
self.assertEqual(split_command(u'echo μμ'), ['echo', 'μμ'])
662671

0 commit comments

Comments
 (0)