Skip to content

Instantly share code, notes, and snippets.

@shivapoudel
Last active October 8, 2019 13:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivapoudel/f10169a5ee26ae4579190307b2dbba00 to your computer and use it in GitHub Desktop.
Save shivapoudel/f10169a5ee26ae4579190307b2dbba00 to your computer and use it in GitHub Desktop.
Docker reset
docker system prune -f --volumes
docker container prune -f
docker container stop $(docker container ls -aq)
docker container rm $(docker container ls -aq)
docker image prune -f -a
docker volume prune -f
docker network prune -f

Docker commands cheetsheet:

Docker reset commands collections:

Removing All Unused Objects

The docker system prune command will remove all stopped containers, all dangling images, and all unused networks.

Commands:

docker system prune -f # Use the -f or --force flag to bypass the prompt.
docker system prune --volumes # Use the --volumes flag to remove all unused volumes.

Removing Docker Containers

Docker containers are not automatically removed when you stop them unless you start the container using the --rm flag.

Commands:

docker container ls -a # Lists all active and inactive containers by passing the -a flag.
docker container prune -f # Use the -f or --force flag to bypass the prompt.
docker container stop $(docker container ls -aq) # Stop all running containers.
docker container rm $(docker container ls -aq) # Once all containers are stopped you can remove them.

Removing Docker Images

To remove one or more Docker images use the docker images ls command to find the ID of the images you want to remove.

Commands:

docker image ls -a # Lists all the docker images.
docker image prune -f # Use the -f or --force flag to bypass the prompt.
docker image prune -a # Use the -a flag to remove all images without at least one container associated to them.

Removing Docker Volumes

To remove one or more Docker volumes use the docker volume ls command to find the ID of the volumes you want to remove.

Commands:

docker volume ls # Lists all the docker volumes.
docker volume prune -f # Use the -f or --force flag to bypass the prompt.

Removing Docker Networks

To remove one or more Docker networks use the docker network ls command to find the ID of the networks you want to remove.

Commands:

docker network ls # Lists all the docker volumes.
docker network prune -f # Use the -f or --force flag to bypass the prompt.

Conclusion

In this guide, we have shown you some of the common commands for removing Docker containers, images, volumes, and networks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment