This question is related to Should I be concerned about excess, non-running, Docker containers?.
I'm wondering how to remove old containers. The docker rm 3e552code34a
lets you remove a single one, but I have lots already. docker rm --help
doesn't give a selection option (like all, or by image name).
Maybe there is a directory in which these containers are stored where I can delete them easily manually?
https://github.com/HardySimpson/docker-cleanup
Docker cleanup
A tiny all-in-one shell, which removes:
Intend to run as a crontab job
Feature
<none>:<none>
images2>/dev/null
or notFirst, stop running containers before attempting to remove them
Remove running containers
You could use
kill
instead ofstop
. In my case I preferstop
since I tend to rerun them vs. creating a new one every time so I try to shut them down nicely.Note: Trying to stop a container will give you an error:
Remove all containers
For anyone interested, I took the example from qkrijger and turned it into a clear all (stop and remove all)
UPDATED 2017 (NEWEST)
This - 2017 (OLD) way
To remove ALL STOPPED CONTAINERS
To remove ALL CONTAINERS (STOPPED AND NON STOPPED)
Here is my
docker-cleanup
script, which removes untagged containers and images. Please check the source for any updates.Source: https://github.com/blueyed/dotfiles/blob/master/usr/bin/docker-cleanup