Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
302cb78f
Unverified
Kaydet (Commit)
302cb78f
authored
Kas 09, 2018
tarafından
Joffrey F
Kaydeden (comit)
GitHub
Kas 09, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #2172 from docker/fix_docs
Documentation fixes
üst
5467658b
35b94607
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
137 additions
and
48 deletions
+137
-48
container.py
docker/api/container.py
+30
-16
daemon.py
docker/api/daemon.py
+3
-3
image.py
docker/api/image.py
+9
-9
service.py
docker/api/service.py
+2
-1
containers.py
docker/models/containers.py
+26
-13
images.py
docker/models/images.py
+1
-1
containers.py
docker/types/containers.py
+56
-0
daemon.py
docker/types/daemon.py
+1
-1
utils.py
docker/utils/utils.py
+5
-2
api.rst
docs/api.rst
+2
-0
utils_test.py
tests/unit/utils_test.py
+2
-2
No files found.
docker/api/container.py
Dosyayı görüntüle @
302cb78f
...
@@ -473,16 +473,12 @@ class ContainerApiMixin(object):
...
@@ -473,16 +473,12 @@ class ContainerApiMixin(object):
signals and reaps processes
signals and reaps processes
init_path (str): Path to the docker-init binary
init_path (str): Path to the docker-init binary
ipc_mode (str): Set the IPC mode for the container.
ipc_mode (str): Set the IPC mode for the container.
isolation (str): Isolation technology to use. Default: `None`.
isolation (str): Isolation technology to use. Default: ``None``.
links (dict or list of tuples): Either a dictionary mapping name
links (dict): Mapping of links using the
to alias or as a list of ``(name, alias)`` tuples.
``{'container': 'alias'}`` format. The alias is optional.
log_config (dict): Logging configuration, as a dictionary with
Containers declared in this dict will be linked to the new
keys:
container using the provided alias. Default: ``None``.
log_config (LogConfig): Logging configuration
- ``type`` The logging driver name.
- ``config`` A dictionary of configuration for the logging
driver.
lxc_conf (dict): LXC config.
lxc_conf (dict): LXC config.
mem_limit (float or str): Memory limit. Accepts float values
mem_limit (float or str): Memory limit. Accepts float values
(which represent the memory limit of the created container in
(which represent the memory limit of the created container in
...
@@ -543,7 +539,7 @@ class ContainerApiMixin(object):
...
@@ -543,7 +539,7 @@ class ContainerApiMixin(object):
}
}
ulimits (:py:class:`list`): Ulimits to set inside the container,
ulimits (:py:class:`list`): Ulimits to set inside the container,
as a list of
dict
s.
as a list of
:py:class:`docker.types.Ulimit` instance
s.
userns_mode (str): Sets the user namespace mode for the container
userns_mode (str): Sets the user namespace mode for the container
when user namespace remapping option is enabled. Supported
when user namespace remapping option is enabled. Supported
values are: ``host``
values are: ``host``
...
@@ -611,9 +607,10 @@ class ContainerApiMixin(object):
...
@@ -611,9 +607,10 @@ class ContainerApiMixin(object):
aliases (:py:class:`list`): A list of aliases for this endpoint.
aliases (:py:class:`list`): A list of aliases for this endpoint.
Names in that list can be used within the network to reach the
Names in that list can be used within the network to reach the
container. Defaults to ``None``.
container. Defaults to ``None``.
links (:py:class:`list`): A list of links for this endpoint.
links (dict): Mapping of links for this endpoint using the
Containers declared in this list will be linked to this
``{'container': 'alias'}`` format. The alias is optional.
container. Defaults to ``None``.
Containers declared in this dict will be linked to this
container using the provided alias. Defaults to ``None``.
ipv4_address (str): The IP address of this container on the
ipv4_address (str): The IP address of this container on the
network, using the IPv4 protocol. Defaults to ``None``.
network, using the IPv4 protocol. Defaults to ``None``.
ipv6_address (str): The IP address of this container on the
ipv6_address (str): The IP address of this container on the
...
@@ -628,7 +625,7 @@ class ContainerApiMixin(object):
...
@@ -628,7 +625,7 @@ class ContainerApiMixin(object):
>>> endpoint_config = client.create_endpoint_config(
>>> endpoint_config = client.create_endpoint_config(
aliases=['web', 'app'],
aliases=['web', 'app'],
links=
['app_db']
,
links=
{'app_db': 'db', 'another': None}
,
ipv4_address='132.65.0.123'
ipv4_address='132.65.0.123'
)
)
...
@@ -697,6 +694,18 @@ class ContainerApiMixin(object):
...
@@ -697,6 +694,18 @@ class ContainerApiMixin(object):
Raises:
Raises:
:py:class:`docker.errors.APIError`
:py:class:`docker.errors.APIError`
If the server returns an error.
If the server returns an error.
Example:
>>> c = docker.APIClient()
>>> f = open('./sh_bin.tar', 'wb')
>>> bits, stat = c.get_archive(container, '/bin/sh')
>>> print(stat)
{'name': 'sh', 'size': 1075464, 'mode': 493,
'mtime': '2018-10-01T15:37:48-07:00', 'linkTarget': ''}
>>> for chunk in bits:
... f.write(chunk)
>>> f.close()
"""
"""
params
=
{
params
=
{
'path'
:
path
'path'
:
path
...
@@ -1074,7 +1083,8 @@ class ContainerApiMixin(object):
...
@@ -1074,7 +1083,8 @@ class ContainerApiMixin(object):
Args:
Args:
container (str): The container to stream statistics from
container (str): The container to stream statistics from
decode (bool): If set to true, stream will be decoded into dicts
decode (bool): If set to true, stream will be decoded into dicts
on the fly. False by default.
on the fly. Only applicable if ``stream`` is True.
False by default.
stream (bool): If set to false, only the current stats will be
stream (bool): If set to false, only the current stats will be
returned instead of a stream. True by default.
returned instead of a stream. True by default.
...
@@ -1088,6 +1098,10 @@ class ContainerApiMixin(object):
...
@@ -1088,6 +1098,10 @@ class ContainerApiMixin(object):
return
self
.
_stream_helper
(
self
.
_get
(
url
,
stream
=
True
),
return
self
.
_stream_helper
(
self
.
_get
(
url
,
stream
=
True
),
decode
=
decode
)
decode
=
decode
)
else
:
else
:
if
decode
:
raise
errors
.
InvalidArgument
(
"decode is only available in conjuction with stream=True"
)
return
self
.
_result
(
self
.
_get
(
url
,
params
=
{
'stream'
:
False
}),
return
self
.
_result
(
self
.
_get
(
url
,
params
=
{
'stream'
:
False
}),
json
=
True
)
json
=
True
)
...
...
docker/api/daemon.py
Dosyayı görüntüle @
302cb78f
...
@@ -42,8 +42,8 @@ class DaemonApiMixin(object):
...
@@ -42,8 +42,8 @@ class DaemonApiMixin(object):
Example:
Example:
>>> for event in client.events()
>>> for event in client.events(
decode=True
)
... print
event
... print
(event)
{u'from': u'image/with:tag',
{u'from': u'image/with:tag',
u'id': u'container-id',
u'id': u'container-id',
u'status': u'start',
u'status': u'start',
...
@@ -54,7 +54,7 @@ class DaemonApiMixin(object):
...
@@ -54,7 +54,7 @@ class DaemonApiMixin(object):
>>> events = client.events()
>>> events = client.events()
>>> for event in events:
>>> for event in events:
... print
event
... print
(event)
>>> # and cancel from another thread
>>> # and cancel from another thread
>>> events.close()
>>> events.close()
"""
"""
...
...
docker/api/image.py
Dosyayı görüntüle @
302cb78f
...
@@ -32,7 +32,7 @@ class ImageApiMixin(object):
...
@@ -32,7 +32,7 @@ class ImageApiMixin(object):
Example:
Example:
>>> image = cli.get_image("busybox:latest")
>>> image = cli.get_image("busybox:latest")
>>> f = open('/tmp/busybox-latest.tar', 'w')
>>> f = open('/tmp/busybox-latest.tar', 'w
b
')
>>> for chunk in image:
>>> for chunk in image:
>>> f.write(chunk)
>>> f.write(chunk)
>>> f.close()
>>> f.close()
...
@@ -352,8 +352,8 @@ class ImageApiMixin(object):
...
@@ -352,8 +352,8 @@ class ImageApiMixin(object):
Example:
Example:
>>> for line in cli.pull('busybox', stream=True):
>>> for line in cli.pull('busybox', stream=True
, decode=True
):
... print(json.dumps(
json.loads(line)
, indent=4))
... print(json.dumps(
line
, indent=4))
{
{
"status": "Pulling image (latest) from busybox",
"status": "Pulling image (latest) from busybox",
"progressDetail": {},
"progressDetail": {},
...
@@ -428,12 +428,12 @@ class ImageApiMixin(object):
...
@@ -428,12 +428,12 @@ class ImageApiMixin(object):
If the server returns an error.
If the server returns an error.
Example:
Example:
>>> for line in cli.push('yourname/app', stream=True):
>>> for line in cli.push('yourname/app', stream=True
, decode=True
):
... print
line
... print
(line)
{
"status":"Pushing repository yourname/app (1 tags)"
}
{
'status': 'Pushing repository yourname/app (1 tags)'
}
{
"status":"Pushing","progressDetail":{},"id":"511136ea3c5a"
}
{
'status': 'Pushing','progressDetail': {}, 'id': '511136ea3c5a'
}
{
"status":"Image already pushed, skipping","progressDetail"
:{},
{
'status': 'Image already pushed, skipping', 'progressDetail'
:{},
"id":"511136ea3c5a"
}
'id': '511136ea3c5a'
}
...
...
"""
"""
...
...
docker/api/service.py
Dosyayı görüntüle @
302cb78f
...
@@ -197,7 +197,8 @@ class ServiceApiMixin(object):
...
@@ -197,7 +197,8 @@ class ServiceApiMixin(object):
into the service inspect output.
into the service inspect output.
Returns:
Returns:
``True`` if successful.
(dict): A dictionary of the server-side representation of the
service, including all relevant properties.
Raises:
Raises:
:py:class:`docker.errors.APIError`
:py:class:`docker.errors.APIError`
...
...
docker/models/containers.py
Dosyayı görüntüle @
302cb78f
...
@@ -15,7 +15,12 @@ from .resource import Collection, Model
...
@@ -15,7 +15,12 @@ from .resource import Collection, Model
class
Container
(
Model
):
class
Container
(
Model
):
""" Local representation of a container object. Detailed configuration may
be accessed through the :py:attr:`attrs` attribute. Note that local
attributes are cached; users may call :py:meth:`reload` to
query the Docker daemon for the current properties, causing
:py:attr:`attrs` to be refreshed.
"""
@property
@property
def
name
(
self
):
def
name
(
self
):
"""
"""
...
@@ -228,6 +233,17 @@ class Container(Model):
...
@@ -228,6 +233,17 @@ class Container(Model):
Raises:
Raises:
:py:class:`docker.errors.APIError`
:py:class:`docker.errors.APIError`
If the server returns an error.
If the server returns an error.
Example:
>>> f = open('./sh_bin.tar', 'wb')
>>> bits, stat = container.get_archive('/bin/sh')
>>> print(stat)
{'name': 'sh', 'size': 1075464, 'mode': 493,
'mtime': '2018-10-01T15:37:48-07:00', 'linkTarget': ''}
>>> for chunk in bits:
... f.write(chunk)
>>> f.close()
"""
"""
return
self
.
client
.
api
.
get_archive
(
self
.
id
,
path
,
chunk_size
)
return
self
.
client
.
api
.
get_archive
(
self
.
id
,
path
,
chunk_size
)
...
@@ -380,7 +396,8 @@ class Container(Model):
...
@@ -380,7 +396,8 @@ class Container(Model):
Args:
Args:
decode (bool): If set to true, stream will be decoded into dicts
decode (bool): If set to true, stream will be decoded into dicts
on the fly. False by default.
on the fly. Only applicable if ``stream`` is True.
False by default.
stream (bool): If set to false, only the current stats will be
stream (bool): If set to false, only the current stats will be
returned instead of a stream. True by default.
returned instead of a stream. True by default.
...
@@ -574,15 +591,11 @@ class ContainerCollection(Collection):
...
@@ -574,15 +591,11 @@ class ContainerCollection(Collection):
``{"label1": "value1", "label2": "value2"}``) or a list of
``{"label1": "value1", "label2": "value2"}``) or a list of
names of labels to set with empty values (e.g.
names of labels to set with empty values (e.g.
``["label1", "label2"]``)
``["label1", "label2"]``)
links (dict or list of tuples): Either a dictionary mapping name
links (dict): Mapping of links using the
to alias or as a list of ``(name, alias)`` tuples.
``{'container': 'alias'}`` format. The alias is optional.
log_config (dict): Logging configuration, as a dictionary with
Containers declared in this dict will be linked to the new
keys:
container using the provided alias. Default: ``None``.
log_config (LogConfig): Logging configuration.
- ``type`` The logging driver name.
- ``config`` A dictionary of configuration for the logging
driver.
mac_address (str): MAC address to assign to the container.
mac_address (str): MAC address to assign to the container.
mem_limit (int or str): Memory limit. Accepts float values
mem_limit (int or str): Memory limit. Accepts float values
(which represent the memory limit of the created container in
(which represent the memory limit of the created container in
...
@@ -691,8 +704,8 @@ class ContainerCollection(Collection):
...
@@ -691,8 +704,8 @@ class ContainerCollection(Collection):
}
}
tty (bool): Allocate a pseudo-TTY.
tty (bool): Allocate a pseudo-TTY.
ulimits (:py:class:`list`): Ulimits to set inside the container,
as
ulimits (:py:class:`list`): Ulimits to set inside the container,
a
list of dict
s.
a
s a list of :py:class:`docker.types.Ulimit` instance
s.
user (str or int): Username or UID to run commands as inside the
user (str or int): Username or UID to run commands as inside the
container.
container.
userns_mode (str): Sets the user namespace mode for the container
userns_mode (str): Sets the user namespace mode for the container
...
...
docker/models/images.py
Dosyayı görüntüle @
302cb78f
...
@@ -84,7 +84,7 @@ class Image(Model):
...
@@ -84,7 +84,7 @@ class Image(Model):
Example:
Example:
>>> image = cli.get_image("busybox:latest")
>>> image = cli.get_image("busybox:latest")
>>> f = open('/tmp/busybox-latest.tar', 'w')
>>> f = open('/tmp/busybox-latest.tar', 'w
b
')
>>> for chunk in image:
>>> for chunk in image:
>>> f.write(chunk)
>>> f.write(chunk)
>>> f.close()
>>> f.close()
...
...
docker/types/containers.py
Dosyayı görüntüle @
302cb78f
...
@@ -23,6 +23,36 @@ class LogConfigTypesEnum(object):
...
@@ -23,6 +23,36 @@ class LogConfigTypesEnum(object):
class
LogConfig
(
DictType
):
class
LogConfig
(
DictType
):
"""
Configure logging for a container, when provided as an argument to
:py:meth:`~docker.api.container.ContainerApiMixin.create_host_config`.
You may refer to the
`official logging driver documentation <https://docs.docker.com/config/containers/logging/configure/>`_
for more information.
Args:
type (str): Indicate which log driver to use. A set of valid drivers
is provided as part of the :py:attr:`LogConfig.types`
enum. Other values may be accepted depending on the engine version
and available logging plugins.
config (dict): A driver-dependent configuration dictionary. Please
refer to the driver's documentation for a list of valid config
keys.
Example:
>>> from docker.types import LogConfig
>>> lc = LogConfig(type=LogConfig.types.JSON, config={
... 'max-size': '1g',
... 'labels': 'production_status,geo'
... })
>>> hc = client.create_host_config(log_config=lc)
>>> container = client.create_container('busybox', 'true',
... host_config=hc)
>>> client.inspect_container(container)['HostConfig']['LogConfig']
{'Type': 'json-file', 'Config': {'labels': 'production_status,geo', 'max-size': '1g'}}
"""
# flake8: noqa
types
=
LogConfigTypesEnum
types
=
LogConfigTypesEnum
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
...
@@ -50,14 +80,40 @@ class LogConfig(DictType):
...
@@ -50,14 +80,40 @@ class LogConfig(DictType):
return
self
[
'Config'
]
return
self
[
'Config'
]
def
set_config_value
(
self
,
key
,
value
):
def
set_config_value
(
self
,
key
,
value
):
""" Set a the value for ``key`` to ``value`` inside the ``config``
dict.
"""
self
.
config
[
key
]
=
value
self
.
config
[
key
]
=
value
def
unset_config
(
self
,
key
):
def
unset_config
(
self
,
key
):
""" Remove the ``key`` property from the ``config`` dict. """
if
key
in
self
.
config
:
if
key
in
self
.
config
:
del
self
.
config
[
key
]
del
self
.
config
[
key
]
class
Ulimit
(
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 <http://tinyurl.me/ZWRkM2Ztwlykf>`_.
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
)
>>> client.inspect_container(container)['HostConfig']['Ulimits']
[{'Name': 'nproc', 'Hard': 0, 'Soft': 1024}]
"""
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
name
=
kwargs
.
get
(
'name'
,
kwargs
.
get
(
'Name'
))
name
=
kwargs
.
get
(
'name'
,
kwargs
.
get
(
'Name'
))
soft
=
kwargs
.
get
(
'soft'
,
kwargs
.
get
(
'Soft'
))
soft
=
kwargs
.
get
(
'soft'
,
kwargs
.
get
(
'Soft'
))
...
...
docker/types/daemon.py
Dosyayı görüntüle @
302cb78f
...
@@ -15,7 +15,7 @@ class CancellableStream(object):
...
@@ -15,7 +15,7 @@ class CancellableStream(object):
Example:
Example:
>>> events = client.events()
>>> events = client.events()
>>> for event in events:
>>> for event in events:
... print
event
... print
(event)
>>> # and cancel from another thread
>>> # and cancel from another thread
>>> events.close()
>>> events.close()
"""
"""
...
...
docker/utils/utils.py
Dosyayı görüntüle @
302cb78f
...
@@ -386,7 +386,10 @@ def convert_filters(filters):
...
@@ -386,7 +386,10 @@ def convert_filters(filters):
v
=
'true'
if
v
else
'false'
v
=
'true'
if
v
else
'false'
if
not
isinstance
(
v
,
list
):
if
not
isinstance
(
v
,
list
):
v
=
[
v
,
]
v
=
[
v
,
]
result
[
k
]
=
v
result
[
k
]
=
[
str
(
item
)
if
not
isinstance
(
item
,
six
.
string_types
)
else
item
for
item
in
v
]
return
json
.
dumps
(
result
)
return
json
.
dumps
(
result
)
...
@@ -441,7 +444,7 @@ def normalize_links(links):
...
@@ -441,7 +444,7 @@ def normalize_links(links):
if
isinstance
(
links
,
dict
):
if
isinstance
(
links
,
dict
):
links
=
six
.
iteritems
(
links
)
links
=
six
.
iteritems
(
links
)
return
[
'{0}:{1}'
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
links
)]
return
[
'{0}:{1}'
.
format
(
k
,
v
)
if
v
else
k
for
k
,
v
in
sorted
(
links
)]
def
parse_env_file
(
env_file
):
def
parse_env_file
(
env_file
):
...
...
docs/api.rst
Dosyayı görüntüle @
302cb78f
...
@@ -140,6 +140,7 @@ Configuration types
...
@@ -140,6 +140,7 @@ Configuration types
.. autoclass:: Healthcheck
.. autoclass:: Healthcheck
.. autoclass:: IPAMConfig
.. autoclass:: IPAMConfig
.. autoclass:: IPAMPool
.. autoclass:: IPAMPool
.. autoclass:: LogConfig
.. autoclass:: Mount
.. autoclass:: Mount
.. autoclass:: Placement
.. autoclass:: Placement
.. autoclass:: Privileges
.. autoclass:: Privileges
...
@@ -151,4 +152,5 @@ Configuration types
...
@@ -151,4 +152,5 @@ Configuration types
.. autoclass:: SwarmExternalCA
.. autoclass:: SwarmExternalCA
.. autoclass:: SwarmSpec(*args, **kwargs)
.. autoclass:: SwarmSpec(*args, **kwargs)
.. autoclass:: TaskTemplate
.. autoclass:: TaskTemplate
.. autoclass:: Ulimit
.. autoclass:: UpdateConfig
.. autoclass:: UpdateConfig
tests/unit/utils_test.py
Dosyayı görüntüle @
302cb78f
...
@@ -457,8 +457,8 @@ class UtilsTest(unittest.TestCase):
...
@@ -457,8 +457,8 @@ class UtilsTest(unittest.TestCase):
tests
=
[
tests
=
[
({
'dangling'
:
True
},
'{"dangling": ["true"]}'
),
({
'dangling'
:
True
},
'{"dangling": ["true"]}'
),
({
'dangling'
:
"true"
},
'{"dangling": ["true"]}'
),
({
'dangling'
:
"true"
},
'{"dangling": ["true"]}'
),
({
'exited'
:
0
},
'{"exited": [
0
]}'
),
({
'exited'
:
0
},
'{"exited": [
"0"
]}'
),
({
'exited'
:
[
0
,
1
]},
'{"exited": [
0, 1
]}'
),
({
'exited'
:
[
0
,
1
]},
'{"exited": [
"0", "1"
]}'
),
]
]
for
filters
,
expected
in
tests
:
for
filters
,
expected
in
tests
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment