Class: Docker::API::Volumes

Inherits:
Collection show all
Defined in:
lib/docker/api/collections/volumes.rb

Overview

The volumes on a daemon.

Instance Attribute Summary

Attributes inherited from Collection

#client

Instance Method Summary collapse

Methods inherited from Collection

#exist?, #find, #initialize, #to_s

Constructor Details

This class inherits a constructor from Docker::API::Collection

Instance Method Details

#all(filters: nil) ⇒ Array<Docker::API::Volume>

Parameters:

  • filters (Hash, nil) (defaults to: nil)

    daemon-side filters

Returns:



12
13
14
15
16
17
# File 'lib/docker/api/collections/volumes.rb', line 12

def all(filters: nil)
  payload = operations.volume_list(filters: filters).json!
  Array(payload["Volumes"]).map do |entry|
    Volume.new(client: client, raw: entry, partial: false)
  end
end

#create(name = nil, driver: nil, labels: nil, driver_opts: nil) ⇒ Docker::API::Volume

Create a volume.

Parameters:

  • name (String, nil) (defaults to: nil)

    a name, or nil to let the daemon choose one

  • driver (String, nil) (defaults to: nil)

    the driver to back it with

  • labels (Hash, nil) (defaults to: nil)

    labels for the volume

  • driver_opts (Hash, nil) (defaults to: nil)

    driver-specific options

Returns:



38
39
40
41
42
43
44
45
# File 'lib/docker/api/collections/volumes.rb', line 38

def create(name = nil, driver: nil, labels: nil, driver_opts: nil)
  body = {
    "Name" => name, "Driver" => driver,
    "Labels" => labels, "DriverOpts" => driver_opts
  }.compact

  Volume.new(client: client, raw: operations.volume_create(body: body).json, partial: false)
end

#get(name) ⇒ Docker::API::Volume

Parameters:

  • name (String)

    the volume's name

Returns:

Raises:



27
28
29
# File 'lib/docker/api/collections/volumes.rb', line 27

def get(name)
  Volume.new(client: client, raw: operations.volume_inspect(name: name).json, partial: false)
end

#prune(filters: nil) ⇒ Hash

Returns what was deleted and how much space it freed.

Parameters:

  • filters (Hash, nil) (defaults to: nil)

    which volumes to consider

Returns:

  • (Hash)

    what was deleted and how much space it freed



49
50
51
# File 'lib/docker/api/collections/volumes.rb', line 49

def prune(filters: nil)
  operations.volume_prune(filters: filters).json
end

#warnings(filters: nil) ⇒ Array<String>

Returns names of volumes the daemon could not inspect.

Returns:

  • (Array<String>)

    names of volumes the daemon could not inspect



20
21
22
# File 'lib/docker/api/collections/volumes.rb', line 20

def warnings(filters: nil)
  Array(operations.volume_list(filters: filters).json!["Warnings"])
end