Today I Learned

ins8s

Remove unused Docker containers and images

1) Before deleting all the containers, force stop them:

docker ps -q -a | xargs docker stop

2) Then delete the containers using:

docker ps -q -a | xargs docker rm

3) Now delete all the dangling images using:

docker rmi $(docker images | grep “^<none>” | awk ‘{print $3}’)

One-liner

docker kill $(docker ps -q) && docker rm $(docker ps -a -q) && docker rmi $(docker images -q)