module CIDE::Docker

Simple docker client helper

Public Class Methods

id(str) click to toggle source

Generates a valid id for docker from any string

# File lib/cide/docker.rb, line 7
def self.id(str)
  str.to_s.downcase.gsub(/[^a-z0-9\-_.]/, '_')
end

Public Instance Methods

docker(*args, verbose: false, capture: false) click to toggle source
# File lib/cide/docker.rb, line 31
def docker(*args, verbose: false, capture: false)
  cmd = (['docker'] + args).map(&:to_s)
  p cmd if verbose

  if capture
    r, w = IO.pipe
    pid = Process.spawn(*cmd, out: w)
    w.close
    return r.read
  else
    pid = Process.spawn(*cmd)

    return 0
  end
ensure
  Process.wait(pid)
  exitstatus = $?.exitstatus
  raise Error, exitstatus if exitstatus > 0
end
docker_image_ids(filter_by: false) click to toggle source
# File lib/cide/docker.rb, line 22
def docker_image_ids(filter_by: false)
  args = ['--no-trunc']
  args << ['--filter', filter_by] if filter_by
  lines = docker('images', *args, capture: true).lines[1..-1]
  lines
    .map { |line| line.split(/\s+/) }
    .map { |line| line[2] }
end