Class: EacDocker::Container
- Inherits:
-
Object
- Object
- EacDocker::Container
- Defined in:
- lib/eac_docker/container.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #hostname ⇒ Object
- #immutable_constructor_args ⇒ Object
- #immutable_volume ⇒ Object
- #logs ⇒ String
- #on_detached ⇒ Object
- #run_command ⇒ Object
- #run_command_args ⇒ Object
- #stop ⇒ Object
- #volume(left_part, right_part = nil) ⇒ Object
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/eac_docker/container.rb', line 9 def id @id end |
Instance Method Details
#hostname ⇒ Object
19 20 21 22 23 24 |
# File 'lib/eac_docker/container.rb', line 19 def hostname ::EacDocker::Executables.docker.command( 'inspect', '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}', id ).execute!.strip end |
#immutable_constructor_args ⇒ Object
13 14 15 |
# File 'lib/eac_docker/container.rb', line 13 def immutable_constructor_args [image] end |
#immutable_volume ⇒ Object
17 |
# File 'lib/eac_docker/container.rb', line 17 alias immutable_volume volume |
#logs ⇒ String
27 28 29 |
# File 'lib/eac_docker/container.rb', line 27 def logs ::EacDocker::Executables.docker.command('logs', id).execute! end |
#on_detached ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/eac_docker/container.rb', line 31 def on_detached command = ::EacDocker::Executables.docker.command(*(%w[run --detach] + run_command_args)) self.id = command.execute!.strip begin yield(self) ensure stop end end |
#run_command ⇒ Object
45 46 47 |
# File 'lib/eac_docker/container.rb', line 45 def run_command ::EacDocker::Executables.docker.command('run', *run_command_args) end |
#run_command_args ⇒ Object
49 50 51 52 53 |
# File 'lib/eac_docker/container.rb', line 49 def run_command_args %w[boolean capabilities envs volumes] .inject([]) { |a, e| a + send("run_command_#{e}_args") } + [image.provide.id] + command_args end |
#stop ⇒ Object
55 56 57 |
# File 'lib/eac_docker/container.rb', line 55 def stop ::EacDocker::Executables.docker.command('stop', id).execute! end |
#volume(left_part, right_part = nil) ⇒ Object
41 42 43 |
# File 'lib/eac_docker/container.rb', line 41 def volume(left_part, right_part = nil) immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" }) end |