Class: Inspec::Resources::DockerContainer

Inherits:
Object
  • Object
show all
Includes:
DockerObject
Defined in:
lib/resources/docker_container.rb

Instance Method Summary collapse

Methods included from DockerObject

#exist?, #id

Constructor Details

#initialize(opts = {}) ⇒ DockerContainer

Returns a new instance of DockerContainer.



32
33
34
35
36
37
38
39
# File 'lib/resources/docker_container.rb', line 32

def initialize(opts = {})
  # if a string is provided, we expect it is the name
  if opts.is_a?(String)
    @opts = { name: opts }
  else
    @opts = opts
  end
end

Instance Method Details

#commandObject



57
58
59
60
61
62
# File 'lib/resources/docker_container.rb', line 57

def command
  return unless object_info.entries.length == 1

  cmd = object_info.commands[0]
  cmd.slice(1, cmd.length - 2)
end

#imageObject



64
65
66
# File 'lib/resources/docker_container.rb', line 64

def image
  object_info.images[0] if object_info.entries.length == 1
end

#labelsObject



49
50
51
# File 'lib/resources/docker_container.rb', line 49

def labels
  object_info.labels[0] if object_info.entries.length == 1
end

#portsObject



53
54
55
# File 'lib/resources/docker_container.rb', line 53

def ports
  object_info.ports[0] if object_info.entries.length == 1
end

#repoObject



68
69
70
# File 'lib/resources/docker_container.rb', line 68

def repo
  parse_components_from_image(image)[:repo] if object_info.entries.size == 1
end

#running?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/resources/docker_container.rb', line 41

def running?
  status.downcase.start_with?('up') if object_info.entries.length == 1
end

#statusObject



45
46
47
# File 'lib/resources/docker_container.rb', line 45

def status
  object_info.status[0] if object_info.entries.length == 1
end

#tagObject



72
73
74
# File 'lib/resources/docker_container.rb', line 72

def tag
  parse_components_from_image(image)[:tag] if object_info.entries.size == 1
end

#to_sObject



76
77
78
79
# File 'lib/resources/docker_container.rb', line 76

def to_s
  name = @opts[:name] || @opts[:id]
  "Docker Container #{name}"
end