module Docker
Constants
- USER_NAME
Public Instance Methods
ID(input)
click to toggle source
# File lib/docker.rb, line 27 def ID(input) case input when String Id.create(input) when ->(obj){obj.respond_to?(:id)} Id.create(input.id) end end
PATH(input)
click to toggle source
# File lib/docker.rb, line 36 def PATH(input) case input when String Path.new(input) when Path input end end
all_containers()
click to toggle source
# File lib/docker.rb, line 141 def all_containers `docker ps -a`.split("\n")[1..-1] end
build(app_path, image_tag = nil)
click to toggle source
delegate to Image
# File lib/docker.rb, line 46 def build(app_path, image_tag = nil) path = PATH(app_path) image_tag ||= path.name Image.build(path, image_tag) end
containers(mode = :all)
click to toggle source
# File lib/docker.rb, line 122 def containers(mode = :all) containers = case mode when :all all_containers when :stopped all_containers.select { |container| container =~ /Exited/ } when :paused all_containers.select { |container| container =~ /(Paused)/ } when :running `docker ps`.split("\n")[1..-1] .select { |container| container !~ /(Paused)/} else raise ArgumentError, "Bad Argument: #{mode}" end containers.map do |container| Container.new(container[0..11]).to_klass end end
find_container(options = {})
click to toggle source
# File lib/docker.rb, line 97 def find_container(options = {}) validate_search_parameters(options) containers.find do |container| found = true options.each do |option,value| found = false unless container.send(option) == value end found end end
find_containers(options = {})
click to toggle source
# File lib/docker.rb, line 108 def find_containers(options = {}) klass = options.delete(:klass) validate_search_parameters(options) kontainers = containers kontainers.map! { |container| klass.load_from(container) } if klass kontainers.select { |container| found = true options.each do |option, value| found = false unless container.send(option) === value end found }.compact end
find_image(options = {})
click to toggle source
# File lib/docker.rb, line 85 def find_image(options = {}) klass = options.delete(:klass) || :image validate_search_parameters(options) images(klass).find do |image| found = true options.each do |option,value| found = false unless image.send(option) == value end found end end
images(response_type = :image)
click to toggle source
# File lib/docker.rb, line 57 def images(response_type = :image) images = `docker images`.split("\n")[1..-1] images.map do |image| id = image.match(/^[^\s]+\s+[^\s]+\s+([^\s]+)/)[1] repo = image.match(/^[a-zA-Z0-9\/\-_\.<>]+/)[0] tag = image.match(/^[^\s]+\s+([^\s]+)/)[1] case response_type when :repository Repository.new(id, repo) when :tag Tag.new(id, repo, tag) when :image Image.new(id) end end end
inspekt(id)
click to toggle source
# File lib/docker.rb, line 74 def inspekt(id) inspekt = Inspect.new(id.to_s) inspekt.inspekt ? inspekt : NullInspect.new end
run(image, options = "", command = "")
click to toggle source
delegate to Container
# File lib/docker.rb, line 53 def run(image, options = "", command = "") Container.run(image.to_s, options, command) end
validate_search_parameters(options)
click to toggle source
# File lib/docker.rb, line 79 def validate_search_parameters(options) bad_args = options.keys.select {|key| key.to_s.end_with?('!')} raise ArgumentError, 'bang method given ' + "as option: #{bad_args.join(', ')}" unless bad_args.empty? end