Skip to content

Instantly share code, notes, and snippets.

@jedprentice
Created December 10, 2019 21:58
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 jedprentice/5facbf2f8b036bcd06843a6d38695700 to your computer and use it in GitHub Desktop.
Save jedprentice/5facbf2f8b036bcd06843a6d38695700 to your computer and use it in GitHub Desktop.
#!/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