Skip to content

Instantly share code, notes, and snippets.

@ampedandwired
Created February 12, 2017 22:33
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 ampedandwired/d3025a4b6f66bdebbd027b7014210d74 to your computer and use it in GitHub Desktop.
Save ampedandwired/d3025a4b6f66bdebbd027b7014210d74 to your computer and use it in GitHub Desktop.
Docker cleanup
#!/bin/bash
# Remove exited containers
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
# Remove dangling containers
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
# Remove unused images (https://github.com/docker/docker/issues/9054#issuecomment-184246090)
docker rmi $(grep -xvf <(docker ps -a --format '{{.Image}}') <(docker images | tail -n +2 | grep -v '<none>' | awk '{ print $1":"$2 }'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment