Class: Dockdev::Container
- Inherits:
-
Object
- Object
- Dockdev::Container
- Defined in:
- lib/dockdev/container.rb
Instance Method Summary collapse
- #attach_and_exec(opts = {}) ⇒ Object
- #destroy ⇒ Object
- #has_container? ⇒ Boolean
-
#initialize(name) ⇒ Container
constructor
A new instance of Container.
- #name ⇒ Object
- #running? ⇒ Boolean
- #start_with_command(opts = {}) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(name) ⇒ Container
Returns a new instance of Container.
7 8 9 10 |
# File 'lib/dockdev/container.rb', line 7 def initialize(name) @cont_name = name @cmd_fact = Docker::Cli::CommandFactory.new end |
Instance Method Details
#attach_and_exec(opts = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dockdev/container.rb', line 34 def attach_and_exec(opts = {}) optss = { tty: true, interactive: true } @cmd_fact.run_command_in_running_container(@cont_name, opts[:command], optss).run end |
#destroy ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/dockdev/container.rb', line 63 def destroy res = @cmd_fact.delete_container(@cont_name).run if res.success? not res.is_out_stream_empty? else raise Error, "Command delete container failed with error : #{res.err_stream}" end end |
#has_container? ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/dockdev/container.rb', line 16 def has_container? res = @cmd_fact.find_from_all_container(@cont_name, exact_name: true).run if res.success? not res.is_out_stream_empty? else raise Error, "Command find from all container failed with error : #{res.err_stream}" end end |
#name ⇒ Object
12 13 14 |
# File 'lib/dockdev/container.rb', line 12 def name @cont_name end |
#running? ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'lib/dockdev/container.rb', line 25 def running? res = @cmd_fact.find_running_container(@cont_name, exact_name: true).run if res.success? not res.is_out_stream_empty? else raise Error, "Command to check is container running failed with error : #{res.err_stream}" end end |
#start_with_command(opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dockdev/container.rb', line 42 def start_with_command(opts = {}) res = @cmd_fact.start_container(@cont_name).run if res.success? and not res.is_out_stream_empty? attach_and_exec(opts) else raise Error, "Command to start container failed with error : #{res.err_stream}" end end |
#stop ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/dockdev/container.rb', line 54 def stop res = @cmd_fact.stop_container(@cont_name).run if res.success? not res.is_out_stream_empty? else raise Error, "Command stop container failed with error : #{res.err_stream}" end end |