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.
11 12 13 |
# File 'lib/eac_docker/container.rb', line 11 def id @id end |
Instance Method Details
#hostname ⇒ Object
20 21 22 23 24 25 |
# File 'lib/eac_docker/container.rb', line 20 def hostname ::EacDocker::Executables.docker.command( 'inspect', '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}', id ).execute!.strip end |
#immutable_constructor_args ⇒ Object
14 15 16 |
# File 'lib/eac_docker/container.rb', line 14 def immutable_constructor_args [image] end |
#immutable_volume ⇒ Object
18 |
# File 'lib/eac_docker/container.rb', line 18 alias immutable_volume volume |
#logs ⇒ String
28 29 30 |
# File 'lib/eac_docker/container.rb', line 28 def logs ::EacDocker::Executables.docker.command('logs', id).execute! end |
#on_detached ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/eac_docker/container.rb', line 32 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
46 47 48 |
# File 'lib/eac_docker/container.rb', line 46 def run_command ::EacDocker::Executables.docker.command('run', *run_command_args) end |
#run_command_args ⇒ Object
50 51 52 53 54 |
# File 'lib/eac_docker/container.rb', line 50 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
56 57 58 |
# File 'lib/eac_docker/container.rb', line 56 def stop ::EacDocker::Executables.docker.command('stop', id).execute! end |
#volume(left_part, right_part = nil) ⇒ Object
42 43 44 |
# File 'lib/eac_docker/container.rb', line 42 def volume(left_part, right_part = nil) immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" }) end |