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?
The official way is:
The Docker maintainers have indicated there will be no command for this - and you compose the commands like that:
To remove ALL containers without crying:
Removing all containers from Windows shell:
You can remove only stopped containers. Stop all of them in the beginning
docker stop $(docker ps -a -q)
Then you can remove
docker rm $(docker ps -a -q)
New way: spotify/docker-gc play the trick.
It has supported environmental settings
Forcing deletion of images that have multiple tags
Forcing deletion of containers
Excluding Recently Exited Containers and Images From Garbage Collection
This setting also prevents the removal of images that have been created less than GRACE_PERIOD_SECONDS seconds ago.
Dry run
Cleaning up orphaned container volumes CLEAN_UP_VOLUMES=1
Reference: docker-gc
Old way to do:
delete old, non-running containers
delete all images associated with non-running docker containers
cleanup orphaned docker volumes for docker version 1.10.x and above
Based on time period