Module: DockerCompose

Defined in:
lib/version.rb,
lib/docker-compose.rb

Class Method Summary collapse

Class Method Details

.docker_clientObject

Get Docker client object



12
13
14
# File 'lib/docker-compose.rb', line 12

def self.docker_client
  Docker
end

.load(filepath, do_load_running_containers = false) ⇒ Object

Load a given docker-compose file. Returns a new Compose object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/docker-compose.rb', line 20

def self.load(filepath, do_load_running_containers = false)
  unless File.exist?(filepath)
    raise ArgumentError, 'Compose file doesn\'t exists'
  end

  compose = Compose.new

  # Create containers from compose file
  _compose_entries = YAML.load_file(filepath)

  if _compose_entries
    _compose_entries.each do |entry|
      compose.add_container(create_container(entry))
    end
  end

  # Load running containers
  if do_load_running_containers
    Docker::Container
      .all(all: true)
      .select {|c| c.info['Names'].last.match(/\A\/#{ComposeUtils.dir_name}\w*/) }
      .each do |container|
        compose.add_container(load_running_container(container))
    end
  end

  # Perform containers linkage
  compose.link_containers

  compose
end

.versionObject



2
3
4
# File 'lib/version.rb', line 2

def self.version
  "1.1.0"
end