Class: ComposeContainer
- Inherits:
-
Object
- Object
- ComposeContainer
- Defined in:
- lib/docker-compose/models/compose_container.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
-
#add_dependency(dependency) ⇒ Object
Add a dependency to this container (i.e. a container that must be started before this one).
-
#delete ⇒ Object
Delete the container.
-
#exist? ⇒ Boolean
Check if the container exists or not.
-
#initialize(hash_attributes) ⇒ ComposeContainer
constructor
A new instance of ComposeContainer.
-
#kill ⇒ Object
Kill the container.
-
#running? ⇒ Boolean
Check if a container is already running or not.
-
#start ⇒ Object
Start the container and its dependencies.
-
#stats ⇒ Object
Return container statistics.
-
#stop ⇒ Object
Stop the container.
Constructor Details
#initialize(hash_attributes) ⇒ ComposeContainer
Returns a new instance of ComposeContainer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/docker-compose/models/compose_container.rb', line 9 def initialize(hash_attributes) @attributes = { label: hash_attributes[:label], name: hash_attributes[:name].nil? ? hash_attributes[:label] : hash_attributes[:name], image: ComposeUtils.format_image(hash_attributes[:image]), build: hash_attributes[:build], links: ComposeUtils.format_links(hash_attributes[:links]), ports: prepare_ports(hash_attributes[:ports]), volumes: hash_attributes[:volumes], command: ComposeUtils.format_command(hash_attributes[:command]), environment: prepare_environment(hash_attributes[:environment]) }.reject{ |key, value| value.nil? } # Docker client variables @internal_image = nil @container = nil @dependencies = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/docker-compose/models/compose_container.rb', line 7 def attributes @attributes end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
7 8 9 |
# File 'lib/docker-compose/models/compose_container.rb', line 7 def container @container end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/docker-compose/models/compose_container.rb', line 7 def dependencies @dependencies end |
Instance Method Details
#add_dependency(dependency) ⇒ Object
Add a dependency to this container (i.e. a container that must be started before this one)
219 220 221 |
# File 'lib/docker-compose/models/compose_container.rb', line 219 def add_dependency(dependency) @dependencies << dependency end |
#delete ⇒ Object
Delete the container
210 211 212 213 |
# File 'lib/docker-compose/models/compose_container.rb', line 210 def delete @container.delete(:force => true) unless @container.nil? @container = nil end |
#exist? ⇒ Boolean
Check if the container exists or not
240 241 242 |
# File 'lib/docker-compose/models/compose_container.rb', line 240 def exist? !@container.nil? end |
#kill ⇒ Object
Kill the container
203 204 205 |
# File 'lib/docker-compose/models/compose_container.rb', line 203 def kill @container.kill unless @container.nil? end |
#running? ⇒ Boolean
Check if a container is already running or not
233 234 235 |
# File 'lib/docker-compose/models/compose_container.rb', line 233 def running? @container.nil? ? false : self.stats['State']['Running'] end |
#start ⇒ Object
Start the container and its dependencies
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/docker-compose/models/compose_container.rb', line 178 def start # Start dependencies @dependencies.each do |dependency| dependency.start unless dependency.running? end # Create a container object if @container.nil? prepare_image prepare_container end @container.start unless @container.nil? end |
#stats ⇒ Object
Return container statistics
226 227 228 |
# File 'lib/docker-compose/models/compose_container.rb', line 226 def stats @container.json end |
#stop ⇒ Object
Stop the container
196 197 198 |
# File 'lib/docker-compose/models/compose_container.rb', line 196 def stop @container.stop unless @container.nil? end |