Created
December 10, 2019 21:58
-
-
Save jedprentice/5facbf2f8b036bcd06843a6d38695700 to your computer and use it in GitHub Desktop.
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 | |
# Don't remove devops containers that might be databases | |
def database_container?(line) | |
line.match?(/postgres/) || line.match?(/redis/) | |
end | |
# docker ps -f "before=containerId" | grep expression > /var/tmp/containers.txt | |
File.open('/var/tmp/containers.txt').each do |line| | |
next if database_container?(line) | |
name = line.split.last | |
puts "Removing #{name}" | |
system("docker rm -f #{name}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment