class Docker::Volume

class represents a Docker Volume

Public Class Methods

all(opts = {}, conn = Docker.connection) click to toggle source

/volumes endpoint returns an array of hashes incapsulated in an Volumes tag

# File lib/docker/volume.rb, line 26
def all(opts = {}, conn = Docker.connection)
  resp = conn.get('/volumes')
  json = Docker::Util.parse_json(resp) || {}
  hashes = json['Volumes'] || []
  hashes.map { |hash| new(conn, hash) }
end
create(name, opts = {}, conn = Docker.connection) click to toggle source

creates a volume with an arbitrary name

# File lib/docker/volume.rb, line 34
def create(name, opts = {}, conn = Docker.connection)
  opts['Name'] = name
  resp = conn.post('/volumes/create', {}, body: MultiJson.dump(opts))
  hash = Docker::Util.parse_json(resp) || {}
  new(conn, hash)
end
get(name, conn = Docker.connection) click to toggle source

get details for a single volume

# File lib/docker/volume.rb, line 19
def get(name, conn = Docker.connection)
  resp = conn.get("/volumes/#{name}")
  hash = Docker::Util.parse_json(resp) || {}
  new(conn, hash)
end
prune(conn = Docker.connection) click to toggle source
# File lib/docker/volume.rb, line 41
def prune(conn = Docker.connection)
  conn.post("/volumes/prune")
end

Public Instance Methods

normalize_hash(hash) click to toggle source
# File lib/docker/volume.rb, line 12
def normalize_hash(hash)
  hash['id'] ||= hash['Name']
end
remove(opts = {}, conn = Docker.connection) click to toggle source

/volumes/volume_name doesnt return anything

# File lib/docker/volume.rb, line 8
def remove(opts = {}, conn = Docker.connection)
  conn.delete("/volumes/#{id}")
end