Skip to content

Commit 049e7e1

Browse files
committed
Improved LogConfig documentation
Signed-off-by: Joffrey F <[email protected]>
1 parent 9467fa4 commit 049e7e1

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

docker/api/container.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,7 @@ def create_host_config(self, *args, **kwargs):
476476
isolation (str): Isolation technology to use. Default: `None`.
477477
links (dict or list of tuples): Either a dictionary mapping name
478478
to alias or as a list of ``(name, alias)`` tuples.
479-
log_config (dict): Logging configuration, as a dictionary with
480-
keys:
481-
482-
- ``type`` The logging driver name.
483-
- ``config`` A dictionary of configuration for the logging
484-
driver.
485-
479+
log_config (LogConfig): Logging configuration
486480
lxc_conf (dict): LXC config.
487481
mem_limit (float or str): Memory limit. Accepts float values
488482
(which represent the memory limit of the created container in

docker/models/containers.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
576576
``["label1", "label2"]``)
577577
links (dict or list of tuples): Either a dictionary mapping name
578578
to alias or as a list of ``(name, alias)`` tuples.
579-
log_config (dict): Logging configuration, as a dictionary with
580-
keys:
581-
582-
- ``type`` The logging driver name.
583-
- ``config`` A dictionary of configuration for the logging
584-
driver.
585-
579+
log_config (LogConfig): Logging configuration.
586580
mac_address (str): MAC address to assign to the container.
587581
mem_limit (int or str): Memory limit. Accepts float values
588582
(which represent the memory limit of the created container in

docker/types/containers.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ class LogConfigTypesEnum(object):
2323

2424

2525
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
2656
types = LogConfigTypesEnum
2757

2858
def __init__(self, **kwargs):
@@ -50,9 +80,13 @@ def config(self):
5080
return self['Config']
5181

5282
def set_config_value(self, key, value):
83+
""" Set a the value for ``key`` to ``value`` inside the ``config``
84+
dict.
85+
"""
5386
self.config[key] = value
5487

5588
def unset_config(self, key):
89+
""" Remove the ``key`` property from the ``config`` dict. """
5690
if key in self.config:
5791
del self.config[key]
5892

@@ -71,9 +105,14 @@ class Ulimit(DictType):
71105
72106
Example:
73107
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+
77116
"""
78117
def __init__(self, **kwargs):
79118
name = kwargs.get('name', kwargs.get('Name'))

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Configuration types
140140
.. autoclass:: Healthcheck
141141
.. autoclass:: IPAMConfig
142142
.. autoclass:: IPAMPool
143+
.. autoclass:: LogConfig
143144
.. autoclass:: Mount
144145
.. autoclass:: Placement
145146
.. autoclass:: Privileges

0 commit comments

Comments
 (0)