Volumes

Manage volumes on the server.

Methods available on client.volumes:

class VolumeCollection
create(name, **kwargs)

Create a volume.

Parameters:
  • 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:

The volume created.

Return type:

(Volume)

Raises:

docker.errors.APIError – If the server returns an error.

Example

>>> volume = client.volumes.create(name='foobar', driver='local',
        driver_opts={'foo': 'bar', 'baz': 'false'},
        labels={"key": "value"})
get(volume_id)

Get a volume.

Parameters:

volume_id (str) – Volume name.

Returns:

The volume.

Return type:

(Volume)

Raises:
  • docker.errors.NotFound – If the volume does not exist.
  • docker.errors.APIError – If the server returns an error.
list(**kwargs)

List volumes. Similar to the docker volume ls command.

Parameters:filters (dict) – Server-side list filtering options.
Returns:The volumes.
Return type:(list of Volume)
Raises:docker.errors.APIError – If the server returns an error.

Volume objects

class Volume

A volume.

id

The ID of the object.

short_id

The ID of the object, truncated to 10 characters.

name

The name of the volume.

attrs

The raw representation of this object from the server.

reload()

Load this object from the server again and update attrs with the new data.

remove()

Remove this volume.