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 29 30 |
# 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? } prepare_compose_labels # 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)
251 252 253 |
# File 'lib/docker-compose/models/compose_container.rb', line 251 def add_dependency(dependency) @dependencies << dependency end |
#delete ⇒ Object
Delete the container
242 243 244 245 |
# File 'lib/docker-compose/models/compose_container.rb', line 242 def delete @container.delete(:force => true) unless @container.nil? @container = nil end |
#exist? ⇒ Boolean
Check if the container exists or not
272 273 274 |
# File 'lib/docker-compose/models/compose_container.rb', line 272 def exist? !@container.nil? end |
#kill ⇒ Object
Kill the container
235 236 237 |
# File 'lib/docker-compose/models/compose_container.rb', line 235 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)
36 37 38 |
# File 'lib/docker-compose/models/compose_container.rb', line 36 def loaded_from_environment? attributes[:loaded_from_environment] end |
#running? ⇒ Boolean
Check if a container is already running or not
265 266 267 |
# File 'lib/docker-compose/models/compose_container.rb', line 265 def running? @container.nil? ? false : self.stats['State']['Running'] end |
#start ⇒ Object
Start the container and its dependencies
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/docker-compose/models/compose_container.rb', line 210 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
258 259 260 |
# File 'lib/docker-compose/models/compose_container.rb', line 258 def stats @container.json end |
#stop ⇒ Object
Stop the container
228 229 230 |
# File 'lib/docker-compose/models/compose_container.rb', line 228 def stop @container.stop unless @container.nil? end |