Skip to content
Closed
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
16 changes: 12 additions & 4 deletions docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def create_container(self, image, command=None, hostname=None, user=None,
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None,
mac_address=None, labels=None, volume_driver=None):
mac_address=None, labels=None, volume_driver=None,
cgroup_parent=None):

if isinstance(volumes, six.string_types):
volumes = [volumes, ]
Expand All @@ -240,7 +241,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
memswap_limit, cpuset, host_config, mac_address, labels,
volume_driver
volume_driver, cgroup_parent
)
return self.create_container_from_config(config, name)

Expand Down Expand Up @@ -737,7 +738,7 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
dns=None, dns_search=None, volumes_from=None, network_mode=None,
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
security_opt=None, ulimits=None):
security_opt=None, ulimits=None, cgroup_parent=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue against adding this - we've deprecated passing host config arguments in start, and will probably remove it entirely in a future version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shin- Good to know. Can you please tell how cgroup_parent and other host config arguments be passed ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gladly! You can see the documentation on that topic.


if utils.compare_version('1.10', self._version) < 0:
if dns is not None:
Expand Down Expand Up @@ -775,14 +776,21 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
'ulimits is only supported for API version >= 1.18'
)

if utils.compare_version('1.16', self._version) < 0:
if cgroup_parent is not None:
raise errors.InvalidVersion(
'cgroup_parent is only supported for API version >= 1.16'
)

start_config_kwargs = dict(
binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
publish_all_ports=publish_all_ports, links=links, dns=dns,
privileged=privileged, dns_search=dns_search, cap_add=cap_add,
cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
network_mode=network_mode, restart_policy=restart_policy,
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits
ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits,
cgroup_parent=cgroup_parent
)
start_config = None

Expand Down
8 changes: 6 additions & 2 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def create_host_config(
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
security_opt=None, ulimits=None, log_config=None, mem_limit=None,
memswap_limit=None
memswap_limit=None, cgroup_parent=None
):
host_config = {}

Expand Down Expand Up @@ -495,6 +495,9 @@ def create_host_config(
if lxc_conf is not None:
host_config['LxcConf'] = lxc_conf

if cgroup_parent is not None:
host_config['CgroupParent'] = cgroup_parent

if ulimits is not None:
if not isinstance(ulimits, list):
raise errors.DockerException(
Expand Down Expand Up @@ -551,7 +554,7 @@ def create_container_config(
dns=None, volumes=None, volumes_from=None, network_disabled=False,
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=None, cpuset=None, host_config=None, mac_address=None,
labels=None, volume_driver=None
labels=None, volume_driver=None, cgroup_parent=None
):
if isinstance(command, six.string_types):
command = shlex.split(str(command))
Expand Down Expand Up @@ -672,4 +675,5 @@ def create_container_config(
'MacAddress': mac_address,
'Labels': labels,
'VolumeDriver': volume_driver,
'CgroupParent': cgroup_parent,
}
22 changes: 22 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,28 @@ def test_create_container_with_cpuset(self):
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})

def test_create_container_with_cgroup_parent(self):
try:
self.client.create_container('busybox', 'ls',
cgroup_parent='test')
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))

args = fake_request.call_args
self.assertEqual(args[0][0],
url_prefix + 'containers/create')
self.assertEqual(json.loads(args[1]['data']),
json.loads('''
{"Tty": false, "Image": "busybox",
"Cmd": ["ls"], "AttachStdin": false,
"AttachStderr": true,
"AttachStdout": true, "OpenStdin": false,
"StdinOnce": false,
"NetworkDisabled": false,
"CgroupParent": "test"}'''))
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})

def test_create_container_with_working_dir(self):
try:
self.client.create_container('busybox', 'ls',
Expand Down