How to remove all containers docker

In this article let’s discuss about How to remove all containers docker. Let’s go through the following methods without any delay.

Method 1:

# List all containers (only IDs)
docker ps -aq
# Stop all running containers
docker stop $(docker ps -aq)
# Remove all containers
docker rm $(docker ps -aq)
# Remove all images
docker rmi $(docker images -q)

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar by have a try!

Method 2 :

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

Hope the above solution works.

Realted Posts : Bash for each line of file