Module: MKIt::DockerHelper
- Included in:
- DockerListener, Pod, Service
- Defined in:
- lib/mkit/app/helpers/docker_helper.rb
Instance Method Summary collapse
- #attach_network(network_id, instance_id) ⇒ Object
-
#create_instance(cmd) ⇒ Object
from ERB template.
-
#create_network(network_name) ⇒ Object
network.
-
#create_volume(volume_name) ⇒ Object
volumes.
- #delete_volume(volume_name) ⇒ Object
- #dettach_network(network_id, instance_id) ⇒ Object
- #execute_local(instance_id, cmd) ⇒ Object
- #inspect_instance(instance_id) ⇒ Object
- #inspect_volume(volume_name) ⇒ Object
-
#logs(instance_id) ⇒ Object
logs.
- #network_exists?(network_name) ⇒ Boolean
- #remove_instance(instance) ⇒ Object
- #remove_network(network_id) ⇒ Object
- #start_instance(instance_id) ⇒ Object
- #stop_instance(instance_id) ⇒ Object
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
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 |