Class: Sidedock::Container
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#ports ⇒ Object
Returns the value of attribute ports.
Class Method Summary collapse
Instance Method Summary collapse
- #bash(command) ⇒ Object
-
#initialize(id, port_mapping: {}, **options) ⇒ Container
constructor
A new instance of Container.
- #ip ⇒ Object
- #remove ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(id, port_mapping: {}, **options) ⇒ Container
Returns a new instance of Container.
5 6 7 8 |
# File 'lib/sidedock/container.rb', line 5 def initialize(id, port_mapping: {}, **) @id = id @port_mapping = port_mapping end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/sidedock/container.rb', line 3 def id @id end |
#ports ⇒ Object
Returns the value of attribute ports.
3 4 5 |
# File 'lib/sidedock/container.rb', line 3 def ports @ports end |
Class Method Details
.create(image_name_or_id, options) ⇒ Object
10 11 12 13 14 |
# File 'lib/sidedock/container.rb', line 10 def self.create(image_name_or_id, ) raise "No image name given" unless image_name_or_id.present? id = machine.execute "create -P #{image_name_or_id}" new id, ** end |
.using_image(image) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/sidedock/container.rb', line 46 def self.using_image(image) ps_output = machine.execute "ps -a -q --filter ancestor=#{image.id}" ps_output.each_line.map do |id| new id end end |
Instance Method Details
#bash(command) ⇒ Object
38 39 40 |
# File 'lib/sidedock/container.rb', line 38 def bash(command) machine.execute "exec -t #{@id} bash -c '#{command}'" end |
#ip ⇒ Object
42 43 44 |
# File 'lib/sidedock/container.rb', line 42 def ip machine.ip end |
#remove ⇒ Object
26 27 28 |
# File 'lib/sidedock/container.rb', line 26 def remove machine.execute "rm -f #{@id}" end |
#running? ⇒ Boolean
34 35 36 |
# File 'lib/sidedock/container.rb', line 34 def running? machine.execute('ps -q --no-trunc').include? @id end |
#start ⇒ Object
16 17 18 19 |
# File 'lib/sidedock/container.rb', line 16 def start raise "already started" if running? machine.execute "start #{@id}" end |
#stop ⇒ Object
21 22 23 24 |
# File 'lib/sidedock/container.rb', line 21 def stop raise "not running" unless running? machine.execute "stop #{@id}" end |