class Dockit::Container
Attributes
container[R]
Public Class Methods
clean(force: false, except: [])
click to toggle source
# File lib/dockit/container.rb, line 10 def clean(force: false, except: []) puts "Containers..." except = (except||[]).map { |e| "/#{e}"} list( all: force, filters: force ? nil : {status: [:exited]} ).each do |container| names = container.info['Names'] puts " #{container.id}" if (names & except).count > 0 puts " ... skipping #{names}" next end container.delete(force: true, v: force) end end
find(name: nil, id: nil)
click to toggle source
# File lib/dockit/container.rb, line 28 def find(name: nil, id: nil) unless name || id STDERR.puts "Must specify name or id" exit 1 end list().find do |container| name && container.info['Names'].include?(name) || id && container.id == id end end
list(all: false, filters: nil)
click to toggle source
# File lib/dockit/container.rb, line 6 def list(all: false, filters: nil) Docker::Container.all(all: all, filters: JSON.dump(filters)) end
new(options)
click to toggle source
# File lib/dockit/container.rb, line 41 def initialize(options) @tty = options['Tty'] @container = Docker::Container.create(options) end
Public Instance Methods
destroy()
click to toggle source
# File lib/dockit/container.rb, line 65 def destroy puts "Deleting container #{container.id}" container.delete(force: true, v: true) end
start(options={}, verbose: true, transient: false)
click to toggle source
# File lib/dockit/container.rb, line 46 def start(options={}, verbose: true, transient: false) container.start!(options) if transient if @tty trap("INT") {} STDIN.raw! end container.attach(tty: @tty, stdin: @tty ? STDIN : nil) do |*args| if @tty then print args[0] else msg(*args) end end STDIN.cooked! destroy end end
Private Instance Methods
binds(options)
click to toggle source
# File lib/dockit/container.rb, line 81 def binds(options) return unless options['Volumes'] options['Volumes'].collect do |k, v| "#{Dir.pwd}/#{v}:#{k}" end end
msg(stream, chunk)
click to toggle source
# File lib/dockit/container.rb, line 71 def msg(stream, chunk) pfx = stream.to_s == 'stdout' ? 'INFO: ' : 'ERROR: ' puts pfx + [chunk.sub(/^\n/,'').split("\n")] .flatten .collect(&:rstrip) .reject(&:empty?) .join("\n#{pfx}") end