How to quickly clean-up docker development env?

If you used docker-compose up to start your app. To stop those containers to run:

docker-compose down
docker-compose build --no-cache
docker-compose up -d

Kill all docker containers

This command will kill all running containers

docker container kill $(docker container ls -q)
// or
c=$(docker ps -q) && [[ $c ]] && docker kill $c

Remove all docker containers

The command below will remove all stopped containers

docker container rm $(docker container ls -qa)
// or 
c=$(docker ps -qa) && [[ $c ]] && docker rm $c

Delete docker images

This will remove all images without at least one container associated to them.

docker image prune -a

This will remove all dangling images.

docker image prune

Delete docker volumes

Remove all mounted volumes.

Note: Deleting volumes will wipe out their data. Back up any data that you need before deleting a container.

Perhaps this is something you do not want to do before backing up all important things.

docker volume rm $(docker volume ls -q)
0
Would love your thoughts, please comment.x
()
x