api.volume

Module Contents

Classes

VolumeApiMixin()
class VolumeApiMixin
volumes(filters=None)

List volumes currently registered by the docker daemon. Similar to the docker volume ls command.

Args:
filters (dict): Server-side list filtering options.
Returns:
(dict): Dictionary with list of volume objects as value of the Volumes key.
Raises:
docker.errors.APIError
If the server returns an error.

Example:

>>> cli.volumes()
{u'Volumes': [{u'Driver': u'local',
   u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
   u'Name': u'foobar'},
  {u'Driver': u'local',
   u'Mountpoint': u'/var/lib/docker/volumes/baz/_data',
   u'Name': u'baz'}]}
create_volume(name=None, driver=None, driver_opts=None, labels=None)

Create and register a named volume

Args:
name (str): Name of the volume driver (str): Name of the driver used to create the volume driver_opts (dict): Driver options as a key-value dictionary labels (dict): Labels to set on the volume
Returns:
(dict): The created volume reference object
Raises:
docker.errors.APIError
If the server returns an error.

Example:

>>> volume = cli.create_volume(name='foobar', driver='local',
        driver_opts={'foo': 'bar', 'baz': 'false'},
        labels={"key": "value"})
>>> print(volume)
{u'Driver': u'local',
 u'Labels': {u'key': u'value'},
 u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
 u'Name': u'foobar',
 u'Scope': u'local'}
inspect_volume(name)

Retrieve volume info by name.

Args:
name (str): volume name
Returns:
(dict): Volume information dictionary
Raises:
docker.errors.APIError
If the server returns an error.

Example:

>>> cli.inspect_volume('foobar')
{u'Driver': u'local',
 u'Mountpoint': u'/var/lib/docker/volumes/foobar/_data',
 u'Name': u'foobar'}
prune_volumes(filters=None)

Delete unused volumes

Args:
filters (dict): Filters to process on the prune list.
Returns:
(dict): A dict containing a list of deleted volume names and
the amount of disk space reclaimed in bytes.
Raises:
docker.errors.APIError
If the server returns an error.
remove_volume(name, force=False)

Remove a volume. Similar to the docker volume rm command.

Args:

name (str): The volume’s name force (bool): Force removal of volumes that were already removed

out of band by the volume driver plugin.
Raises:
docker.errors.APIError
If volume failed to remove.