Kaydet (Commit) 0c2aaac3 authored tarafından Alasdair Nicol's avatar Alasdair Nicol

Tidied up code examples in docs

 * Use `cli = Client` everywhere
 * Use Client.create_host_config method
 * Added missing '>'s
Signed-off-by: 's avatarAlasdair Nicol <alasdair@thenicols.net>
üst baaa3e3b
...@@ -4,8 +4,8 @@ To instantiate a `Client` class that will allow you to communicate with a ...@@ -4,8 +4,8 @@ To instantiate a `Client` class that will allow you to communicate with a
Docker daemon, simply do: Docker daemon, simply do:
```python ```python
from docker import Client >>> from docker import Client
c = Client(base_url='unix://var/run/docker.sock') >>> cli = Client(base_url='unix://var/run/docker.sock')
``` ```
**Params**: **Params**:
...@@ -250,9 +250,9 @@ PASSWORD=secret ...@@ -250,9 +250,9 @@ PASSWORD=secret
The utility can be used as follows: The utility can be used as follows:
```python ```python
>> import docker.utils >>> import docker.utils
>> my_envs = docker.utils.parse_env_file('/path/to/file') >>> my_envs = docker.utils.parse_env_file('/path/to/file')
>> docker.utils.create_container_config('1.18', '_mongodb', 'foobar', environment=my_envs) >>> docker.utils.create_container_config('1.18', '_mongodb', 'foobar', environment=my_envs)
``` ```
You can now use this with 'environment' for `create_container`. You can now use this with 'environment' for `create_container`.
...@@ -392,9 +392,9 @@ a dict containing `stat` information on the specified `path`. ...@@ -392,9 +392,9 @@ a dict containing `stat` information on the specified `path`.
```python ```python
>>> import docker >>> import docker
>>> c = docker.Client() >>> cli = docker.Client()
>>> ctnr = c.create_container('busybox', 'true') >>> ctnr = cli.create_container('busybox', 'true')
>>> strm, stat = c.get_archive(ctnr, '/bin/sh') >>> strm, stat = cli.get_archive(ctnr, '/bin/sh')
>>> print(stat) >>> print(stat)
{u'linkTarget': u'', u'mode': 493, u'mtime': u'2015-09-16T12:34:23-07:00', u'name': u'sh', u'size': 962860} {u'linkTarget': u'', u'mode': 493, u'mtime': u'2015-09-16T12:34:23-07:00', u'name': u'sh', u'size': 962860}
``` ```
......
...@@ -15,8 +15,8 @@ You can then instantiate `docker.Client` like this: ...@@ -15,8 +15,8 @@ You can then instantiate `docker.Client` like this:
from docker.client import Client from docker.client import Client
from docker.utils import kwargs_from_env from docker.utils import kwargs_from_env
client = Client(**kwargs_from_env()) cli = Client(**kwargs_from_env())
print client.version() print cli.version()
``` ```
If you're encountering the following error: If you're encountering the following error:
...@@ -33,6 +33,6 @@ from docker.utils import kwargs_from_env ...@@ -33,6 +33,6 @@ from docker.utils import kwargs_from_env
kwargs = kwargs_from_env() kwargs = kwargs_from_env()
kwargs['tls'].assert_hostname = False kwargs['tls'].assert_hostname = False
client = Client(**kwargs) cli = Client(**kwargs)
print client.version() print cli.version()
``` ```
\ No newline at end of file
...@@ -5,8 +5,8 @@ the devices parameter in the `host_config` param in `Client.create_container` ...@@ -5,8 +5,8 @@ the devices parameter in the `host_config` param in `Client.create_container`
as shown below: as shown below:
```python ```python
c.create_container( cli.create_container(
'busybox', 'true', host_config=docker.utils.create_host_config(devices=[ 'busybox', 'true', host_config=cli.create_host_config(devices=[
'/dev/sda:/dev/xvda:rwm' '/dev/sda:/dev/xvda:rwm'
]) ])
) )
......
...@@ -114,7 +114,7 @@ for example: ...@@ -114,7 +114,7 @@ for example:
```python ```python
>>> from docker import Client >>> from docker import Client
>>> c = Client() >>> cli = Client()
>>> c.create_host_config(privileged=True, cap_drop=['MKNOD'], volumes_from=['nostalgic_newton']) >>> cli.create_host_config(privileged=True, cap_drop=['MKNOD'], volumes_from=['nostalgic_newton'])
{'CapDrop': ['MKNOD'], 'LxcConf': None, 'Privileged': True, 'VolumesFrom': ['nostalgic_newton'], 'PublishAllPorts': False} {'CapDrop': ['MKNOD'], 'LxcConf': None, 'Privileged': True, 'VolumesFrom': ['nostalgic_newton'], 'PublishAllPorts': False}
``` ```
...@@ -4,9 +4,9 @@ open inside the container in the `Client().create_container()` method. ...@@ -4,9 +4,9 @@ open inside the container in the `Client().create_container()` method.
Bindings are declared in the `host_config` parameter. Bindings are declared in the `host_config` parameter.
```python ```python
container_id = c.create_container( container_id = cli.create_container(
'busybox', 'ls', ports=[1111, 2222], 'busybox', 'ls', ports=[1111, 2222],
host_config=docker.utils.create_host_config(port_bindings={ host_config=cli.create_host_config(port_bindings={
1111: 4567, 1111: 4567,
2222: None 2222: None
}) })
...@@ -17,22 +17,22 @@ container_id = c.create_container( ...@@ -17,22 +17,22 @@ container_id = c.create_container(
You can limit the host address on which the port will be exposed like such: You can limit the host address on which the port will be exposed like such:
```python ```python
docker.utils.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)}) cli.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)})
``` ```
Or without host port assignment: Or without host port assignment:
```python ```python
docker.utils.create_host_config(port_bindings={1111: ('127.0.0.1',)}) cli.create_host_config(port_bindings={1111: ('127.0.0.1',)})
``` ```
If you wish to use UDP instead of TCP (default), you need to declare ports If you wish to use UDP instead of TCP (default), you need to declare ports
as such in both the config and host config: as such in both the config and host config:
```python ```python
container_id = c.create_container( container_id = cli.create_container(
'busybox', 'ls', ports=[(1111, 'udp'), 2222], 'busybox', 'ls', ports=[(1111, 'udp'), 2222],
host_config=docker.utils.create_host_config(port_bindings={ host_config=cli.create_host_config(port_bindings={
'1111/udp': 4567, 2222: None '1111/udp': 4567, 2222: None
}) })
) )
......
...@@ -5,9 +5,9 @@ the `Client().create_container()` method, and declare mappings in the ...@@ -5,9 +5,9 @@ the `Client().create_container()` method, and declare mappings in the
`host_config` section. `host_config` section.
```python ```python
container_id = c.create_container( container_id = cli.create_container(
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'], 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
host_config=docker.utils.create_host_config(binds={ host_config=cli.create_host_config(binds={
'/home/user1/': { '/home/user1/': {
'bind': '/mnt/vol2', 'bind': '/mnt/vol2',
'mode': 'rw', 'mode': 'rw',
...@@ -24,9 +24,9 @@ You can alternatively specify binds as a list. This code is equivalent to the ...@@ -24,9 +24,9 @@ You can alternatively specify binds as a list. This code is equivalent to the
example above: example above:
```python ```python
container_id = c.create_container( container_id = cli.create_container(
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'], 'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
host_config=docker.utils.create_host_config(binds=[ host_config=cli.create_host_config(binds=[
'/home/user1/:/mnt/vol2', '/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro', '/var/www:/mnt/vol1:ro',
]) ])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment