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.



11
12
13
# File 'lib/eac_docker/container.rb', line 11

def id
  @id
end

Instance Method Details

#hostnameObject



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

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

#immutable_constructor_argsObject



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

def immutable_constructor_args
  [image]
end

#immutable_volumeObject



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

alias immutable_volume volume

#on_detachedObject



27
28
29
30
31
32
33
34
35
# File 'lib/eac_docker/container.rb', line 27

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



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

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

#run_command_argsObject



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

def run_command_args
  run_command_boolean_args + run_command_capabilities_args + run_command_envs_args +
    run_command_volumes_args + [image.provide.id] + command_args
end

#stopObject



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

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

#volume(left_part, right_part = null) ⇒ Object



37
38
39
# File 'lib/eac_docker/container.rb', line 37

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