Remove stopped Docker containers
You could remove all Docker containers like this:
docker rm $(docker ps -a -q)
Note: This will not only remove stopped, but ALL containers. The -a
flag returns all containers while the -q
flag gives only container IDs.
The better way would be to pipe the output to xargs to not execute a subshell:
docker ps -a -q | xargs docker rm
Want to remove more than 1 day old containers?
docker ps -a | grep 'days old' | awk '{print $1}' | xargs docker rm
Written by Aaron Kalin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#