Fix containers low-level documentation examples

I realize that low-level documentation has outdated examples, so I
created issue #2800 to fix that

Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
This commit is contained in:
Felipe Ruhland 2021-04-05 15:31:43 +02:00
parent 0892fcfc12
commit ac9ae1f249
1 changed files with 25 additions and 25 deletions

View File

@ -244,9 +244,9 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
container_id = cli.create_container( container_id = client.api.create_container(
'busybox', 'ls', ports=[1111, 2222], 'busybox', 'ls', ports=[1111, 2222],
host_config=cli.create_host_config(port_bindings={ host_config=client.api.create_host_config(port_bindings={
1111: 4567, 1111: 4567,
2222: None 2222: None
}) })
@ -258,22 +258,22 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
cli.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)}) client.api.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)})
Or without host port assignment: Or without host port assignment:
.. code-block:: python .. code-block:: python
cli.create_host_config(port_bindings={1111: ('127.0.0.1',)}) client.api.create_host_config(port_bindings={1111: ('127.0.0.1',)})
If you wish to use UDP instead of TCP (default), you need to declare If you wish to use UDP instead of TCP (default), you need to declare
ports as such in both the config and host config: ports as such in both the config and host config:
.. code-block:: python .. code-block:: python
container_id = cli.create_container( container_id = client.api.create_container(
'busybox', 'ls', ports=[(1111, 'udp'), 2222], 'busybox', 'ls', ports=[(1111, 'udp'), 2222],
host_config=cli.create_host_config(port_bindings={ host_config=client.api.create_host_config(port_bindings={
'1111/udp': 4567, 2222: None '1111/udp': 4567, 2222: None
}) })
) )
@ -283,7 +283,7 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
cli.create_host_config(port_bindings={ client.api.create_host_config(port_bindings={
1111: [1234, 4567] 1111: [1234, 4567]
}) })
@ -291,7 +291,7 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
cli.create_host_config(port_bindings={ client.api.create_host_config(port_bindings={
1111: [ 1111: [
('192.168.0.100', 1234), ('192.168.0.100', 1234),
('192.168.0.101', 1234) ('192.168.0.101', 1234)
@ -307,9 +307,9 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
container_id = cli.create_container( container_id = client.api.create_container(
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'], 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
host_config=cli.create_host_config(binds={ host_config=client.api.create_host_config(binds={
'/home/user1/': { '/home/user1/': {
'bind': '/mnt/vol2', 'bind': '/mnt/vol2',
'mode': 'rw', 'mode': 'rw',
@ -326,9 +326,9 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
container_id = cli.create_container( container_id = client.api.create_container(
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'], 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
host_config=cli.create_host_config(binds=[ host_config=client.api.create_host_config(binds=[
'/home/user1/:/mnt/vol2', '/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro', '/var/www:/mnt/vol1:ro',
]) ])
@ -346,15 +346,15 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
networking_config = docker_client.create_networking_config({ networking_config = client.api.create_networking_config({
'network1': docker_client.create_endpoint_config( 'network1': client.api.create_endpoint_config(
ipv4_address='172.28.0.124', ipv4_address='172.28.0.124',
aliases=['foo', 'bar'], aliases=['foo', 'bar'],
links=['container2'] links=['container2']
) )
}) })
ctnr = docker_client.create_container( ctnr = client.api.create_container(
img, command, networking_config=networking_config img, command, networking_config=networking_config
) )
@ -581,7 +581,7 @@ class ContainerApiMixin(object):
Example: Example:
>>> cli.create_host_config(privileged=True, cap_drop=['MKNOD'], >>> client.api.create_host_config(privileged=True, cap_drop=['MKNOD'],
volumes_from=['nostalgic_newton']) volumes_from=['nostalgic_newton'])
{'CapDrop': ['MKNOD'], 'LxcConf': None, 'Privileged': True, {'CapDrop': ['MKNOD'], 'LxcConf': None, 'Privileged': True,
'VolumesFrom': ['nostalgic_newton'], 'PublishAllPorts': False} 'VolumesFrom': ['nostalgic_newton'], 'PublishAllPorts': False}
@ -612,11 +612,11 @@ class ContainerApiMixin(object):
Example: Example:
>>> docker_client.create_network('network1') >>> client.api.create_network('network1')
>>> networking_config = docker_client.create_networking_config({ >>> networking_config = client.api.create_networking_config({
'network1': docker_client.create_endpoint_config() 'network1': client.api.create_endpoint_config()
}) })
>>> container = docker_client.create_container( >>> container = client.api.create_container(
img, command, networking_config=networking_config img, command, networking_config=networking_config
) )
@ -650,7 +650,7 @@ class ContainerApiMixin(object):
Example: Example:
>>> endpoint_config = client.create_endpoint_config( >>> endpoint_config = client.api.create_endpoint_config(
aliases=['web', 'app'], aliases=['web', 'app'],
links={'app_db': 'db', 'another': None}, links={'app_db': 'db', 'another': None},
ipv4_address='132.65.0.123' ipv4_address='132.65.0.123'
@ -729,7 +729,7 @@ class ContainerApiMixin(object):
>>> c = docker.APIClient() >>> c = docker.APIClient()
>>> f = open('./sh_bin.tar', 'wb') >>> f = open('./sh_bin.tar', 'wb')
>>> bits, stat = c.get_archive(container, '/bin/sh') >>> bits, stat = c.api.get_archive(container, '/bin/sh')
>>> print(stat) >>> print(stat)
{'name': 'sh', 'size': 1075464, 'mode': 493, {'name': 'sh', 'size': 1075464, 'mode': 493,
'mtime': '2018-10-01T15:37:48-07:00', 'linkTarget': ''} 'mtime': '2018-10-01T15:37:48-07:00', 'linkTarget': ''}
@ -916,7 +916,7 @@ class ContainerApiMixin(object):
.. code-block:: python .. code-block:: python
>>> cli.port('7174d6347063', 80) >>> client.api.port('7174d6347063', 80)
[{'HostIp': '0.0.0.0', 'HostPort': '80'}] [{'HostIp': '0.0.0.0', 'HostPort': '80'}]
""" """
res = self._get(self._url("/containers/{0}/json", container)) res = self._get(self._url("/containers/{0}/json", container))
@ -1095,10 +1095,10 @@ class ContainerApiMixin(object):
Example: Example:
>>> container = cli.create_container( >>> container = client.api.create_container(
... image='busybox:latest', ... image='busybox:latest',
... command='/bin/sleep 30') ... command='/bin/sleep 30')
>>> cli.start(container=container.get('Id')) >>> client.api.start(container=container.get('Id'))
""" """
if args or kwargs: if args or kwargs:
raise errors.DeprecatedMethod( raise errors.DeprecatedMethod(