Class: EacDocker::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_docker/container.rb,
lib/eac_docker/container/exist.rb,
lib/eac_docker/container/identifiers.rb,
lib/eac_docker/container/run_command.rb,
lib/eac_docker/container/start_command.rb

Defined Under Namespace

Modules: Identifiers Classes: Exist, RunCommand, StartCommand

Instance Method Summary collapse

Instance Method Details

#hostnameObject



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

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

#immutable_constructor_argsObject



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

def immutable_constructor_args
  [image]
end

#immutable_volumeObject



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

alias immutable_volume volume

#logsString

Returns:

  • (String)


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

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

#on_detachedObject



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

def on_detached
  self.id = run_command(%w[--detach]).execute!.strip
  begin
    yield(self)
  ensure
    stop
  end
end

#remove_commandString

Force removal of the container identified by #id, if present, or #name.

Returns:

  • (String)

    output of the "docker rm" command.



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

def remove_command
  ::EacDocker::Executables.docker.command('rm', '--force', identifier)
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 = nil) ⇒ Object



39
40
41
# File 'lib/eac_docker/container.rb', line 39

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