Skip to content

Instantly share code, notes, and snippets.

@mohan08p
Last active March 6, 2017 06:27
Show Gist options
  • Save mohan08p/0e6deebbe4b69c1d986630e34df85514 to your computer and use it in GitHub Desktop.
Save mohan08p/0e6deebbe4b69c1d986630e34df85514 to your computer and use it in GitHub Desktop.
How to remove unused Docker containers and images

Till now (docker version 1.12) we are using the following command to delete all the running containers(also, if we want to delete the volumes, we can do that manually using it's respective tag -v in the following command),

Delete all Exited Containers

docker rm $(docker ps -q -f status=exited)

Delete all Stopped Containers

docker rm $(docker ps -a -q)

Delete All Running and Stopped Containers

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Remove all containers, without any criteria

docker container rm $(docker container ps -aq)

But, in version 1.13 and above, for complete system and cleanup, we can directly user the following command,

docker system prune

All unused containers, images, networks and volumes will get deleted. Also, individually i.e. separately, we can do that using the following commands, that clean up the components,

docker container prune
docker image prune
docker network prune
docker volume prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment