Skip to content

Instantly share code, notes, and snippets.

@paulhandy
Last active September 18, 2017 19:20
Show Gist options
  • Save paulhandy/06046f06a1189b2fb5b1e53f3d05b05b to your computer and use it in GitHub Desktop.
Save paulhandy/06046f06a1189b2fb5b1e53f3d05b05b to your computer and use it in GitHub Desktop.
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