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.



35
36
37
38
39
40
41
42
# File 'lib/resources/docker_container.rb', line 35

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



60
61
62
63
64
65
# File 'lib/resources/docker_container.rb', line 60

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

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

#imageObject



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

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

#labelsObject



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

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

#portsObject



56
57
58
# File 'lib/resources/docker_container.rb', line 56

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

#repoObject



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

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

#running?Boolean

Returns:

  • (Boolean)


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

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

#statusObject



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

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

#tagObject



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

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

#to_sObject



79
80
81
82
# File 'lib/resources/docker_container.rb', line 79

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