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.
-
#internal_image ⇒ Object
readonly
Returns the value of attribute internal_image.
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, docker_container = nil) ⇒ ComposeContainer
constructor
A new instance of ComposeContainer.
-
#kill ⇒ Object
Kill the container.
-
#loaded_from_environment? ⇒ Boolean
Returns true if is a container loaded from environment instead compose file (i.e. a running 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, docker_container = nil) ⇒ 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 27 28 |
# File 'lib/docker-compose/models/compose_container.rb', line 9 def initialize(hash_attributes, docker_container = nil) @attributes = { label: hash_attributes[:label], loaded_from_environment: hash_attributes[:loaded_from_environment] || false, name: hash_attributes[:full_name] || ComposeUtils.generate_container_name(hash_attributes[:name], hash_attributes[:label]), 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]), labels: prepare_labels(hash_attributes[:labels]) }.reject{ |key, value| value.nil? } # Docker client variables @internal_image = nil @container = docker_container @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 |
#internal_image ⇒ Object (readonly)
Returns the value of attribute internal_image.
7 8 9 |
# File 'lib/docker-compose/models/compose_container.rb', line 7 def internal_image @internal_image 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)
238 239 240 |
# File 'lib/docker-compose/models/compose_container.rb', line 238 def add_dependency(dependency) @dependencies << dependency end |
#delete ⇒ Object
Delete the container
229 230 231 232 |
# File 'lib/docker-compose/models/compose_container.rb', line 229 def delete @container.delete(:force => true) unless @container.nil? @container = nil end |
#exist? ⇒ Boolean
Check if the container exists or not
259 260 261 |
# File 'lib/docker-compose/models/compose_container.rb', line 259 def exist? !@container.nil? end |
#kill ⇒ Object
Kill the container
222 223 224 |
# File 'lib/docker-compose/models/compose_container.rb', line 222 def kill @container.kill unless @container.nil? end |
#loaded_from_environment? ⇒ Boolean
Returns true if is a container loaded from environment instead compose file (i.e. a running container)
34 35 36 |
# File 'lib/docker-compose/models/compose_container.rb', line 34 def loaded_from_environment? attributes[:loaded_from_environment] end |
#running? ⇒ Boolean
Check if a container is already running or not
252 253 254 |
# File 'lib/docker-compose/models/compose_container.rb', line 252 def running? @container.nil? ? false : self.stats['State']['Running'] end |
#start ⇒ Object
Start the container and its dependencies
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/docker-compose/models/compose_container.rb', line 197 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
245 246 247 |
# File 'lib/docker-compose/models/compose_container.rb', line 245 def stats @container.json end |
#stop ⇒ Object
Stop the container
215 216 217 |
# File 'lib/docker-compose/models/compose_container.rb', line 215 def stop @container.stop unless @container.nil? end |