Skip to content

Instantly share code, notes, and snippets.

@tywkeene
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tywkeene/f2ba39fddf4c1358ce85 to your computer and use it in GitHub Desktop.
Save tywkeene/f2ba39fddf4c1358ce85 to your computer and use it in GitHub Desktop.
A simple command line tool to nuke your docker
#!/usr/bin/env ruby
require 'docker'
actions = {
"rmi" => lambda{|force|
Docker::Image.all.map{|img|
puts img.id[0..12]
img.remove(:force => force)}
},
"rm" => lambda{|force|
Docker::Container.all(:all => true).map{|cont|
puts cont.id[0..12]
cont.delete(:force => force)}
}
}
if ARGV[0].nil? or !ARGV[1].nil? and ARGV[1] != '-f'
puts "Usage: #{__FILE__} <rm -f> <rmi -f> \n"\
"\trm - Remove all containers\n"\
"\trmi - Remove all images\n"\
"\t-f - Force deletion\n"
exit
end
force = (ARGV[1] == '-f') ? true : false
actions[ARGV[0]].call(force)
@tywkeene
Copy link
Author

Be sure to chmod +x and put it in your ~/bin for the best nuking experience

requires the gem docker-api to run (https://github.com/swipely/docker-api)

gem install docker-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment