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 |
# File 'lib/docker-compose/models/compose_container.rb', line 9 def initialize(hash_attributes) @attributes = { label: 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]) }.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)
190 191 192 |
# File 'lib/docker-compose/models/compose_container.rb', line 190 def add_dependency(dependency) @dependencies << dependency end |
#delete ⇒ Object
Delete the container
181 182 183 184 |
# File 'lib/docker-compose/models/compose_container.rb', line 181 def delete @container.delete(:force => true) unless @container.nil? @container = nil end |
#exist? ⇒ Boolean
Check if the container exists or not
211 212 213 |
# File 'lib/docker-compose/models/compose_container.rb', line 211 def exist? !@container.nil? end |
#kill ⇒ Object
Kill the container
174 175 176 |
# File 'lib/docker-compose/models/compose_container.rb', line 174 def kill @container.kill unless @container.nil? end |
#running? ⇒ Boolean
Check if a container is already running or not
204 205 206 |
# File 'lib/docker-compose/models/compose_container.rb', line 204 def running? @container.nil? ? false : self.stats['State']['Running'] end |
#start ⇒ Object
Start the container and its dependencies
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/docker-compose/models/compose_container.rb', line 149 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
197 198 199 |
# File 'lib/docker-compose/models/compose_container.rb', line 197 def stats @container.json end |
#stop ⇒ Object
Stop the container
167 168 169 |
# File 'lib/docker-compose/models/compose_container.rb', line 167 def stop @container.stop unless @container.nil? end |