Class: EacDocker::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_docker/container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/eac_docker/container.rb', line 9

def id
  @id
end

Instance Method Details

#hostnameObject



19
20
21
22
23
24
# File 'lib/eac_docker/container.rb', line 19

def hostname
  ::EacDocker::Executables.docker.command(
    'inspect', '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
    id
  ).execute!.strip
end

#immutable_constructor_argsObject



13
14
15
# File 'lib/eac_docker/container.rb', line 13

def immutable_constructor_args
  [image]
end

#immutable_volumeObject



17
# File 'lib/eac_docker/container.rb', line 17

alias immutable_volume volume

#logsString

Returns:

  • (String)


27
28
29
# File 'lib/eac_docker/container.rb', line 27

def logs
  ::EacDocker::Executables.docker.command('logs', id).execute!
end

#on_detachedObject



31
32
33
34
35
36
37
38
39
# File 'lib/eac_docker/container.rb', line 31

def on_detached
  command = ::EacDocker::Executables.docker.command(*(%w[run --detach] + run_command_args))
  self.id = command.execute!.strip
  begin
    yield(self)
  ensure
    stop
  end
end

#run_commandObject



45
46
47
# File 'lib/eac_docker/container.rb', line 45

def run_command
  ::EacDocker::Executables.docker.command('run', *run_command_args)
end

#run_command_argsObject



49
50
51
52
53
# File 'lib/eac_docker/container.rb', line 49

def run_command_args
  %w[boolean capabilities envs volumes]
    .inject([]) { |a, e| a + send("run_command_#{e}_args") } +
    [image.provide.id] + command_args
end

#stopObject



55
56
57
# File 'lib/eac_docker/container.rb', line 55

def stop
  ::EacDocker::Executables.docker.command('stop', id).execute!
end

#volume(left_part, right_part = nil) ⇒ Object



41
42
43
# File 'lib/eac_docker/container.rb', line 41

def volume(left_part, right_part = nil)
  immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
end