Class: Dockerlib::Remote::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerlib/remote/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket: nil) ⇒ Client

Returns a new instance of Client.



4
5
6
# File 'lib/dockerlib/remote/client.rb', line 4

def initialize(socket: nil)
  @socket = socket || '/var/run/docker.sock'
end

Instance Method Details

#get(path) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dockerlib/remote/client.rb', line 30

def get(path)
  resp = connection.request(method: :get, path: path)
  if resp.status == 200
    {data: load_body(resp)}
  else
    to_server_error resp
  end
end

#inspect_container(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/dockerlib/remote/client.rb', line 19

def inspect_container(name)
  resp = connection.request(method: :get, path: "/containers/#{name}/json")
  if resp.status == 200
    {data: load_body(resp)}
  elsif resp.status == 404
    {code: :no_such_container}
  else
    to_server_error resp
  end
end

#inspect_image(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dockerlib/remote/client.rb', line 8

def inspect_image(name)
  resp = connection.request(method: :get, path: "/images/#{name}/json")
  if resp.status == 200
    {data: load_body(resp)}
  elsif resp.status == 404
    {code: :no_such_image}
  else
    to_server_error resp
  end
end