Module: MKIt::DockerHelper

Included in:
DockerListener, Pod, Service
Defined in:
lib/mkit/app/helpers/docker_helper.rb

Instance Method Summary collapse

Instance Method Details

#attach_network(network_id, instance_id) ⇒ Object



58
59
60
# File 'lib/mkit/app/helpers/docker_helper.rb', line 58

def attach_network(network_id, instance_id)
  MKIt::CmdRunner.run("docker network connect #{network_id} #{instance_id}")
end

#create_instance(cmd) ⇒ Object

from ERB template



8
9
10
# File 'lib/mkit/app/helpers/docker_helper.rb', line 8

def create_instance(cmd)
  MKIt::CmdRunner.run(cmd)
end

#create_network(network_name) ⇒ Object

network



45
46
47
# File 'lib/mkit/app/helpers/docker_helper.rb', line 45

def create_network(network_name)
  MKIt::CmdRunner.run("docker network create #{network_name}")
end

#create_volume(volume_name) ⇒ Object

volumes



70
71
72
# File 'lib/mkit/app/helpers/docker_helper.rb', line 70

def create_volume(volume_name)
  MKIt::CmdRunner.run("docker volume create #{volume_name}")
end

#delete_volume(volume_name) ⇒ Object



74
75
76
# File 'lib/mkit/app/helpers/docker_helper.rb', line 74

def delete_volume(volume_name)
  MKIt::CmdRunner.run("docker volume rm #{volume_name}")
end

#dettach_network(network_id, instance_id) ⇒ Object



54
55
56
# File 'lib/mkit/app/helpers/docker_helper.rb', line 54

def dettach_network(network_id, instance_id)
  MKIt::CmdRunner.run("docker network disconnect #{network_id} #{instance_id}")
end

#execute_local(instance_id, cmd) ⇒ Object



30
31
32
# File 'lib/mkit/app/helpers/docker_helper.rb', line 30

def execute_local(instance_id, cmd)
  MKIt::CmdRunner.run("docker exec -it #{instance_id} #{cmd}")
end

#inspect_instance(instance_id) ⇒ Object



24
25
26
27
28
# File 'lib/mkit/app/helpers/docker_helper.rb', line 24

def inspect_instance(instance_id)
  # this one does not work on ubunto MKIt::CmdRunner.run("docker inspect #{instance_id}")
  x = `docker inspect #{instance_id}`
  JSON.parse(x).first
end

#inspect_volume(volume_name) ⇒ Object



78
79
80
81
# File 'lib/mkit/app/helpers/docker_helper.rb', line 78

def inspect_volume(volume_name)
  x = MKIt::CmdRunner.run("docker volume inspect #{volume_name}")
  JSON.parse(x).first
end

#logs(instance_id) ⇒ Object

logs



37
38
39
# File 'lib/mkit/app/helpers/docker_helper.rb', line 37

def logs(instance_id)
  `docker logs -n 20 #{instance_id}`
end

#network_exists?(network_name) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/mkit/app/helpers/docker_helper.rb', line 49

def network_exists?(network_name)
  x = MKIt::CmdRunner.run('docker network ls')
  x.match(/\b#{network_name}\b/)
end

#remove_instance(instance) ⇒ Object



20
21
22
# File 'lib/mkit/app/helpers/docker_helper.rb', line 20

def remove_instance(instance)
  MKIt::CmdRunner.run("docker rm -f #{instance}")
end

#remove_network(network_id) ⇒ Object



62
63
64
# File 'lib/mkit/app/helpers/docker_helper.rb', line 62

def remove_network(network_id)
  MKIt::CmdRunner.run("docker network rm #{network_id}")
end

#start_instance(instance_id) ⇒ Object



12
13
14
# File 'lib/mkit/app/helpers/docker_helper.rb', line 12

def start_instance(instance_id)
  MKIt::CmdRunner.run("docker start #{instance_id}")
end

#stop_instance(instance_id) ⇒ Object



16
17
18
# File 'lib/mkit/app/helpers/docker_helper.rb', line 16

def stop_instance(instance_id)
  MKIt::CmdRunner.run("docker stop #{instance_id}")
end