Last active
August 29, 2015 14:09
-
-
Save tywkeene/f2ba39fddf4c1358ce85 to your computer and use it in GitHub Desktop.
A simple command line tool to nuke your docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be sure to
chmod +x
and put it in your ~/bin for the best nuking experiencerequires the gem docker-api to run (https://github.com/swipely/docker-api)
gem install docker-api