From 9467fa480902d06e9f5a59d3c3b5770c8940e15c Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 8 Nov 2018 15:32:10 -0800 Subject: [PATCH] Improve ulimits documentation Signed-off-by: Joffrey F --- docker/api/container.py | 2 +- docker/models/containers.py | 4 ++-- docker/types/containers.py | 17 +++++++++++++++++ docs/api.rst | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docker/api/container.py b/docker/api/container.py index c59a6d01..6967a13a 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -543,7 +543,7 @@ class ContainerApiMixin(object): } ulimits (:py:class:`list`): Ulimits to set inside the container, - as a list of dicts. + as a list of :py:class:`docker.types.Ulimit` instances. userns_mode (str): Sets the user namespace mode for the container when user namespace remapping option is enabled. Supported values are: ``host`` diff --git a/docker/models/containers.py b/docker/models/containers.py index f60ba6e2..98c71742 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -691,8 +691,8 @@ class ContainerCollection(Collection): } tty (bool): Allocate a pseudo-TTY. - ulimits (:py:class:`list`): Ulimits to set inside the container, as - a list of dicts. + ulimits (:py:class:`list`): Ulimits to set inside the container, + as a list of :py:class:`docker.types.Ulimit` instances. user (str or int): Username or UID to run commands as inside the container. userns_mode (str): Sets the user namespace mode for the container diff --git a/docker/types/containers.py b/docker/types/containers.py index 9dfea8ce..13eb4ef3 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -58,6 +58,23 @@ class LogConfig(DictType): class Ulimit(DictType): + """ + Create a ulimit declaration to be used with + :py:meth:`~docker.api.container.ContainerApiMixin.create_host_config`. + + Args: + + name (str): Which ulimit will this apply to. A list of valid names can + be found `here `_. + soft (int): The soft limit for this ulimit. Optional. + hard (int): The hard limit for this ulimit. Optional. + + Example: + + nproc_limit = docker.types.Ulimit(name='nproc', soft=1024) + hc = client.create_host_config(ulimits=[nproc_limit]) + container = client.create_container('busybox', 'true', host_config=hc) + """ def __init__(self, **kwargs): name = kwargs.get('name', kwargs.get('Name')) soft = kwargs.get('soft', kwargs.get('Soft')) diff --git a/docs/api.rst b/docs/api.rst index 69312457..2c2391a8 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -151,4 +151,5 @@ Configuration types .. autoclass:: SwarmExternalCA .. autoclass:: SwarmSpec(*args, **kwargs) .. autoclass:: TaskTemplate +.. autoclass:: Ulimit .. autoclass:: UpdateConfig