class Penkit::Docker

Constants

IMAGE_REGEX
NETWORK
REPOSITORY

Public Instance Methods

create_network!() click to toggle source
# File lib/penkit/docker/network.rb, line 3
def create_network!
  system("docker", "network", "create", *network_options, out: File::NULL) unless network_exists?
end
find_all_containers() click to toggle source
# File lib/penkit/docker/ps.rb, line 3
def find_all_containers
  IO.popen(["docker", "ps", "-aq", *filter_options]).readlines.map(&:strip)
end
find_container_names() click to toggle source
# File lib/penkit/docker/ps.rb, line 7
def find_container_names
  IO.popen(["docker", "ps", "-a", "--format", "{{.Names}}", *filter_options]).readlines.map(&:strip)
end
find_running_containers() click to toggle source
# File lib/penkit/docker/ps.rb, line 11
def find_running_containers
  IO.popen(["docker", "ps", "-q", *filter_options]).readlines.map(&:strip)
end
ps(*args) click to toggle source
# File lib/penkit/docker/ps.rb, line 15
def ps(*args)
  exec("docker", "ps", *filter_options, *args)
end
pull(image, options={}) click to toggle source
# File lib/penkit/docker/pull.rb, line 3
def pull(image, options={})
  if options[:quiet]
    system("docker", "pull", image_url(image), out: File::NULL, err: File::NULL)
  else
    system("docker", "pull", image_url(image))
  end
end
rm(*containers) click to toggle source
# File lib/penkit/docker/rm.rb, line 3
def rm(*containers)
  exec("docker", "rm", "--force", *containers)
end
run(image, *args) click to toggle source
# File lib/penkit/docker/start.rb, line 3
def run(image, *args)
  create_network!
  exec("docker", "run", "--rm", "-it", *run_options, image_url(image), *args)
end
start(image, options={}) click to toggle source
# File lib/penkit/docker/start.rb, line 8
def start(image, options={})
  create_network!
  options[:name] ||= unique_name(image)
  puts "Starting container #{options[:name]}"
  exec("docker", "run", "--detach", *run_options(options), image_url(image))
end
stop(*containers) click to toggle source
# File lib/penkit/docker/stop.rb, line 3
def stop(*containers)
  exec("docker", "stop", *containers)
end

Private Instance Methods

filter_options() click to toggle source
# File lib/penkit/docker/ps.rb, line 21
def filter_options
  %w(--filter label=penkit)
end
network_exists?() click to toggle source
# File lib/penkit/docker/network.rb, line 9
def network_exists?
  system("docker", "network", "inspect", NETWORK, out: File::NULL, err: File::NULL)
end
network_options() click to toggle source
# File lib/penkit/docker/network.rb, line 13
def network_options
  %w(--driver bridge) << NETWORK
end
run_options(options={}) click to toggle source
# File lib/penkit/docker/start.rb, line 17
def run_options(options={})
  args = %w(--label penkit=true --network penkit)
  args += ["--name", options[:name], "--hostname", options[:name]] if options[:name]
  args
end