docker ps
--quiet
--all
--filter status=exited
docker rm
docker images
- --quiet
- --all
- --filter dangling=true
docker rmi
Your hacky way is fine.
docker rm `docker ps -a | grep Exited | awk '{print $1 }'`
My hacky way is
docker rm $(docker ps --all | awk '/ago/{print $1}')
A slightly cleaner way is to run docker ps with the --quiet (-q) flag to get just the id number and --filter status=exited to --filter just the exited ones.
docker rm $(docker ps --filter status=exited --quiet) # remove stopped docker processes
or to run docker rm with the --force (-f) flag and docker ps with the --all (-a) flag to shut down even the running ones
docker rm --force $(docker ps --all --quiet) # remove all docker processes
What's probably taking up all that disk space after several failed builds is the images. To conserve disk space on the docker host, periodically remove unused docker images with
docker rmi $(docker images --filter dangling=true --quiet) # clean dangling docker images
or to get more aggressive, you can --force (-f) it to clean up --all (-a) images
docker rmi --force $(docker images --all --quiet) # clean all possible docker images
@analytik 's way of putting it into a .bashrc function seems like a practical idea
function cleanup_docker() {
docker rm --force $(docker ps --all --quiet) # remove all docker processes
docker rmi $(docker images --filter dangling=true --quiet) # clean dangling docker images
}
and if you're in the habit of generating lots of docker images that you don't need, add it to .bash_logout