Skip to content

Instantly share code, notes, and snippets.

@prakhar1989
Last active February 25, 2016 16:56
Show Gist options
  • Save prakhar1989/77322b2902d10c8c4859 to your computer and use it in GitHub Desktop.
Save prakhar1989/77322b2902d10c8c4859 to your computer and use it in GitHub Desktop.
Cleanup docker images
#!/bin/bash
# source: http://blog.yohanliyanage.com/2015/05/docker-clean-up-after-yourself/
# clean up exited containers
docker rm -v $(docker ps -a -q -f status=exited)
# clean up dangling images
docker rmi $(docker images -f "dangling=true" -q)
# clean up volumes
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes
@prakhar1989
Copy link
Author

docker run \
  --restart \
  -e KEEP_IMAGES="ubuntu:14.04 corp/important-image:tag" \
  -v /var/run/docker.sock:/var/run/docker.sock:rw \
  -v /var/lib/docker:/var/lib/docker:rw \
  meltwater/docker-cleanup:latest

Source: http://ebarnouflant.com/posts/1-a-docker-container-to-clean-up-your-docker-containers

@liquidmetal
Copy link

You should put this in your aliases

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