From b5d3556bce4190c9092551a441c1725f36176aec Mon Sep 17 00:00:00 2001 From: Srikalyan Swayampakula Date: Wed, 29 Jun 2016 21:00:19 -0700 Subject: [PATCH] Added support for user namespace. Signed-off-by: Srikalyan Swayampakula --- docker/utils/utils.py | 10 +++++++++- docs/hostconfig.md | 2 ++ tests/unit/utils_test.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index b38cda47..6d9e7218 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -620,7 +620,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, device_write_bps=None, device_read_iops=None, device_write_iops=None, oom_kill_disable=False, shm_size=None, version=None, tmpfs=None, - oom_score_adj=None): + oom_score_adj=None, userns_mode=None): host_config = {} @@ -853,6 +853,14 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None, raise host_config_version_error('tmpfs', '1.22') host_config["Tmpfs"] = convert_tmpfs_mounts(tmpfs) + if userns_mode: + if version_lt(version, '1.23'): + raise host_config_version_error('userns_mode', '1.23') + + if userns_mode != "host": + raise host_config_value_error("userns_mode", userns_mode) + host_config['UsernsMode'] = userns_mode + return host_config diff --git a/docs/hostconfig.md b/docs/hostconfig.md index c1e23533..e996a75b 100644 --- a/docs/hostconfig.md +++ b/docs/hostconfig.md @@ -123,6 +123,8 @@ for example: for more information. * tmpfs: Temporary filesystems to mouunt. See [Using tmpfs](tmpfs.md) for more information. +* userns_mode: Sets the user namespace mode for the container when user namespace remapping option + is enabled. supported values are: host **Returns** (dict) HostConfig dictionary diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 128778f1..61d87b73 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -98,6 +98,16 @@ class HostConfigTest(base.BaseTestCase): InvalidVersion, lambda: create_host_config(version='1.18.3', oom_kill_disable=True)) + def test_create_host_config_with_userns_mode(self): + config = create_host_config(version='1.23', userns_mode='host') + self.assertEqual(config.get('UsernsMode'), 'host') + self.assertRaises( + InvalidVersion, lambda: create_host_config(version='1.22', + userns_mode='host')) + self.assertRaises( + ValueError, lambda: create_host_config(version='1.23', + userns_mode='host12')) + def test_create_host_config_with_oom_score_adj(self): config = create_host_config(version='1.22', oom_score_adj=100) self.assertEqual(config.get('OomScoreAdj'), 100) @@ -602,7 +612,6 @@ class UtilsTest(base.BaseTestCase): class SplitCommandTest(base.BaseTestCase): - def test_split_command_with_unicode(self): self.assertEqual(split_command(u'echo μμ'), ['echo', 'μμ'])