Playing with Docker can leave you with several stopped containers and unneeded, intermediary images. This may waste substantial disk space. This article shows how to efficiently remove such containers and images.
List all exited containers
docker ps -aq -f status=exitedRemove stopped containers
docker ps -aq --no-trunc -f status=exited | xargs docker rmThis command will not remove running containers, only an error message will be printed out for each of them.
Remove dangling/untagged images
docker images -q --filter dangling=true | xargs docker rmiRemove containers created after a specific container
docker ps --since a1bz3768ez7g -q | xargs docker rmRemove containers created before a specific container
docker ps --before a1bz3768ez7g -q | xargs docker rmUse --rm for docker build
Use --rm together with docker build to remove intermediary images
during the build process.