Class: Docker::Container
- Inherits:
-
Object
- Object
- Docker::Container
- Defined in:
- lib/docker/rails/ext/container.rb
Defined Under Namespace
Classes: Compose
Instance Method Summary collapse
- #compose ⇒ Object
- #down? ⇒ Boolean
- #exit_code ⇒ Object
- #name ⇒ Object
-
#refresh! ⇒ Object
FIXME: remove this method when pull #321 is accepted Update the @info hash, which is the only mutable state in this object.
- #status ⇒ Object
- #up? ⇒ Boolean
Instance Method Details
#compose ⇒ Object
55 56 57 58 |
# File 'lib/docker/rails/ext/container.rb', line 55 def compose return nil unless Compose.is_compose_container?(self) @_compose ||= Compose.new(self) end |
#down? ⇒ Boolean
41 42 43 |
# File 'lib/docker/rails/ext/container.rb', line 41 def down? !up? end |
#exit_code ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/docker/rails/ext/container.rb', line 45 def exit_code return nil if up? return nil unless (status =~ /xited/) # Up 10 seconds # Exited (0) 2 seconds ago status =~ /^.* \((\w+)\)/ $1.to_i end |
#name ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docker/rails/ext/container.rb', line 22 def name name = info['Names'][0] unless info['Names'].nil? name = info['Name'] if name.nil? # straight docker containers appear to just use 'Name' # puts "Name: #{info['Name']}" # puts "Names: #{info['Names']}" # puts "Names.nil?: #{info['Names'].nil?}" # puts "Names.length: #{info['Names'].length}" name.gsub(/^\//, '') end |
#refresh! ⇒ Object
FIXME: remove this method when pull #321 is accepted Update the @info hash, which is the only mutable state in this object.
5 6 7 8 9 10 11 12 13 |
# File 'lib/docker/rails/ext/container.rb', line 5 def refresh! other = Docker::Container.all({all: true}, connection).find { |c| c.id.start_with?(self.id) || self.id.start_with?(c.id) } info.merge!(self.json) other && info.merge!(other.info) self end |
#status ⇒ Object
15 16 17 18 19 20 |
# File 'lib/docker/rails/ext/container.rb', line 15 def status # info is cached, return the first one otherwise retrieve a new container and get the status from it refresh! info['Status'] end |
#up? ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/docker/rails/ext/container.rb', line 34 def up? # Up 10 seconds # Exited (0) 2 seconds ago return true if status =~ /^(up|Up)/ false end |