Class: Docker::Container

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

Overview

Object that represents a Docker container, its information and operations.

Instance Method Summary collapse

Methods inherited from Asset

#initialize, #inspect, #to_h, #to_s

Constructor Details

This class inherits a constructor from Docker::Asset

Instance Method Details

#exit_codeInteger

Returns master process exit code.

Returns:

  • (Integer)

    master process exit code



30
31
32
# File 'lib/docker/container.rb', line 30

def exit_code
  @json['State']['ExitCode']
end

#idString

Returns unique SHA256 container hash.

Returns:

  • (String)

    unique SHA256 container hash



5
6
7
# File 'lib/docker/container.rb', line 5

def id
  @json['Id']
end

#imageString

Returns SHA256 hash of image the container is derived from.

Returns:

  • (String)

    SHA256 hash of image the container is derived from



15
16
17
# File 'lib/docker/container.rb', line 15

def image
  @json['Image']
end

#killObject

Raises:



34
35
36
37
# File 'lib/docker/container.rb', line 34

def kill
  raise Error, "Disconnected from session" unless @session
  @session.kill(id)
end

#nameString

Returns human-readable name of container ()minus initial /).

Returns:

  • (String)

    human-readable name of container ()minus initial /)



10
11
12
# File 'lib/docker/container.rb', line 10

def name
  super.sub(/^\//, '')
end

#pidInteger

Returns master process PID.

Returns:

  • (Integer)

    master process PID



25
26
27
# File 'lib/docker/container.rb', line 25

def pid
  @json['State']['Pid']
end

#rmObject

Raises:



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

def rm
  raise Error, "Disconnected from session" unless @session
  @session.rm(id)
end

#startObject

Raises:



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

def start
  raise Error, "Disconnected from session" unless @session
  @session.start(id)
end

#statusString

Returns running, exited, etc.

Returns:

  • (String)

    running, exited, etc



20
21
22
# File 'lib/docker/container.rb', line 20

def status
  @json['State']['Status']
end

#stopObject

Raises:



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

def stop
  raise Error, "Disconnected from session" unless @session
  @session.stop(id)
end