Method: Indocker::Docker.container_id_by_name

Defined in:
lib/indocker/docker.rb

.container_id_by_name(container_name, only_healthy: false) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/indocker/docker.rb', line 74

def container_id_by_name(container_name, only_healthy: false)
  health_args = if only_healthy
    '--filter="health=healthy"'
  end

  command = "docker ps -a #{health_args} --filter=\"status=running\" --filter \"name=#{container_name}$\" -q"

  id = nil

  res = Indocker::Shell.command_with_result(command, Indocker.logger)

  res.stdout.empty? ? nil : res.stdout
end