Class: Superhosting::DockerApi

Inherits:
Object
  • Object
show all
Defined in:
lib/superhosting/docker_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ DockerApi

Returns a new instance of DockerApi.



3
4
5
# File 'lib/superhosting/docker_api.rb', line 3

def initialize(**kwargs)
  @socket = kwargs[:socket] || '/var/run/docker.sock'
end

Instance Method Details

#container_info(name) ⇒ Object



15
16
17
# File 'lib/superhosting/docker_api.rb', line 15

def container_info(name)
  resp_if_success raw_connection.request(method: :get, path: "/containers/#{name}/json")
end

#container_kill(name) ⇒ Object



19
20
21
# File 'lib/superhosting/docker_api.rb', line 19

def container_kill(name)
  resp_if_success raw_connection.request(method: :post, path: "/containers/#{name}/kill")
end

#container_listObject



27
28
29
# File 'lib/superhosting/docker_api.rb', line 27

def container_list
  resp_if_success raw_connection.request(method: :get, path: '/containers/json')
end

#container_rm(name) ⇒ Object



23
24
25
# File 'lib/superhosting/docker_api.rb', line 23

def container_rm(name)
  resp_if_success raw_connection.request(method: :delete, path: "/containers/#{name}")
end

#raw_connectionObject



7
8
9
# File 'lib/superhosting/docker_api.rb', line 7

def raw_connection
  Excon.new('unix:///', socket: @socket)
end

#resp_if_success(resp) ⇒ Object



11
12
13
# File 'lib/superhosting/docker_api.rb', line 11

def resp_if_success(resp)
  JSON.load(resp.body) if resp.status == 200
end