Class: Compose

Inherits:
Object
  • Object
show all
Defined in:
lib/docker-compose/models/compose.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompose

Returns a new instance of Compose.



8
9
10
# File 'lib/docker-compose/models/compose.rb', line 8

def initialize
  @containers = {}
end

Instance Attribute Details

#containersObject (readonly)

Returns the value of attribute containers.



6
7
8
# File 'lib/docker-compose/models/compose.rb', line 6

def containers
  @containers
end

Instance Method Details

#add_container(container) ⇒ Object

Add a new container to compose



17
18
19
20
# File 'lib/docker-compose/models/compose.rb', line 17

def add_container(container)
  @containers[container.attributes[:label]] = container
  true
end

#kill(labels = []) ⇒ Object

Stop a container

This method accepts an array of labels. If labels is informed, only those containers with label present in array will be stopped. Otherwise, all containers are stopped



67
68
69
# File 'lib/docker-compose/models/compose.rb', line 67

def kill(labels  = [])
  call_container_method(:kill, labels)
end

Create link relations among containers



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/docker-compose/models/compose.rb', line 25

def link_containers
  @containers.each_value do |container|
    links = container.attributes[:links]

    next if links.nil?

    links.each do |service, label|
      dependency_container = @containers[service]
      container.add_dependency(dependency_container)
    end
  end
end

#start(labels = []) ⇒ Object

Start a container

This method accepts an array of labels. If labels is informed, only those containers with label present in array will be started. Otherwise, all containers are started



45
46
47
# File 'lib/docker-compose/models/compose.rb', line 45

def start(labels = [])
  call_container_method(:start, labels)
end

#stop(labels = []) ⇒ Object

Stop a container

This method accepts an array of labels. If labels is informed, only those containers with label present in array will be stopped. Otherwise, all containers are stopped



56
57
58
# File 'lib/docker-compose/models/compose.rb', line 56

def stop(labels = [])
  call_container_method(:stop, labels)
end