Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
Clean up old docker instances
docker ps -a | grep Exit | awk '{print $1}' | xargs docker rm
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:
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
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.