@@ -23,6 +23,36 @@ class LogConfigTypesEnum(object):
23
23
24
24
25
25
class LogConfig (DictType ):
26
+ """
27
+ Configure logging for a container, when provided as an argument to
28
+ :py:meth:`~docker.api.container.ContainerApiMixin.create_host_config`.
29
+ You may refer to the
30
+ `official logging driver documentation <https://docs.docker.com/config/containers/logging/configure/>`_
31
+ for more information.
32
+
33
+ Args:
34
+ type (str): Indicate which log driver to use. A set of valid drivers
35
+ is provided as part of the :py:attr:`LogConfig.types`
36
+ enum. Other values may be accepted depending on the engine version
37
+ and available logging plugins.
38
+ config (dict): A driver-dependent configuration dictionary. Please
39
+ refer to the driver's documentation for a list of valid config
40
+ keys.
41
+
42
+ Example:
43
+
44
+ >>> from docker.types import LogConfig
45
+ >>> lc = LogConfig(type=LogConfig.types.JSON, config={
46
+ ... 'max-size': '1g',
47
+ ... 'labels': 'production_status,geo'
48
+ ... })
49
+ >>> hc = client.create_host_config(log_config=lc)
50
+ >>> container = client.create_container('busybox', 'true',
51
+ ... host_config=hc)
52
+ >>> client.inspect_container(container)['HostConfig']['LogConfig']
53
+ {'Type': 'json-file', 'Config': {'labels': 'production_status,geo', 'max-size': '1g'}}
54
+
55
+ """ # flake8: noqa
26
56
types = LogConfigTypesEnum
27
57
28
58
def __init__ (self , ** kwargs ):
@@ -50,9 +80,13 @@ def config(self):
50
80
return self ['Config' ]
51
81
52
82
def set_config_value (self , key , value ):
83
+ """ Set a the value for ``key`` to ``value`` inside the ``config``
84
+ dict.
85
+ """
53
86
self .config [key ] = value
54
87
55
88
def unset_config (self , key ):
89
+ """ Remove the ``key`` property from the ``config`` dict. """
56
90
if key in self .config :
57
91
del self .config [key ]
58
92
@@ -71,9 +105,14 @@ class Ulimit(DictType):
71
105
72
106
Example:
73
107
74
- nproc_limit = docker.types.Ulimit(name='nproc', soft=1024)
75
- hc = client.create_host_config(ulimits=[nproc_limit])
76
- container = client.create_container('busybox', 'true', host_config=hc)
108
+ >>> nproc_limit = docker.types.Ulimit(name='nproc', soft=1024)
109
+ >>> hc = client.create_host_config(ulimits=[nproc_limit])
110
+ >>> container = client.create_container(
111
+ 'busybox', 'true', host_config=hc
112
+ )
113
+ >>> client.inspect_container(container)['HostConfig']['Ulimits']
114
+ [{'Name': 'nproc', 'Hard': 0, 'Soft': 1024}]
115
+
77
116
"""
78
117
def __init__ (self , ** kwargs ):
79
118
name = kwargs .get ('name' , kwargs .get ('Name' ))
0 commit comments