Skip to content

Instantly share code, notes, and snippets.

@paulhandy paulhandy/docker-cleanup
Last active Sep 18, 2017

Embed
What would you like to do?
Clean up old docker instances
from: https://github.com/moby/moby/issues/3456
docker ps -a | grep Exit | awk '{print $1}' | xargs docker rm
https://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers
There is a new feature in Docker 1.13.x called Docker container prune: docker container prune This will do what you want and should work on all platforms the same way.
There is also a Docker system prune, which will clean up containers, images, volumes, and networks all in one command.
Original Answer:
There has been some talk about a Docker cleanup command. You can find the information on this ticket: https://github.com/dotcloud/docker/issues/928
Until that command is available, you can string Docker commands together with other Unix commands to get what you need. Here is an example on how to clean up old containers that are weeks old:
$ docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm
To give credit, where it is due, this example is from https://twitter.com/jpetazzo/status/347431091415703552.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.