Class: Docker::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/rails/ext/container.rb

Defined Under Namespace

Classes: Compose

Instance Method Summary collapse

Instance Method Details

#composeObject



47
48
49
50
# File 'lib/docker/rails/ext/container.rb', line 47

def compose
  return nil unless Compose.is_compose_container?(self)
  @_compose ||= Compose.new(self)
end

#down?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/docker/rails/ext/container.rb', line 33

def down?
  !up?
end

#exit_codeObject



37
38
39
40
41
42
43
44
45
# File 'lib/docker/rails/ext/container.rb', line 37

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

#nameObject



22
23
24
# File 'lib/docker/rails/ext/container.rb', line 22

def name
  info['Names'][0].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

#statusObject



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

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/docker/rails/ext/container.rb', line 26

def up?
  #  Up 10 seconds
  #  Exited (0) 2 seconds ago
  return true if status =~ /^(up|Up)/
  false
end