Remove All Containers In Docker

Containers are an easy way to run some applications in a lightweight way. A lot of containers are created in daily usage and we may need to remove these containers. In this tutorial, we examine how to remove all containers.

List All Containers

Before removing all containers we can list all containers by using the docker ps command.

$ docker ps -aq

Stop All Running Containers

Before removing all containers we can stop all running containers in order to remove them properly. The docker stop command is used to stop all containers.

$ docker stop $(docker ps -aq)

Remove All Containers

The docker rm command is used to remove specified containers. All containers are specified with the $docker ps -aq command and provided to the “docker rm” command.

$ docker rm $(docker ps -aq)

Remove All Container Images

Every container has its own image created to store data permanently. The docker rmi command is used to remove the docker image. With the following command, all docker images can be removed.

$ docker rmi $(docker images -q)

Leave a Comment