Home » Docker » How to Remove Exited Containers in Docker? (3 Examples)

How to Remove Exited Containers in Docker? (3 Examples)

The following are the 3 command line examples to remove exited containers in Docker.

Example 1: Remove Exited Containers Using Prune

Execute the following command to remove existed container docker:

docker container prune

Example 2:

The below command first searches for the exited containers and then deletes them.

(docker ps -a |findstr Exited) | foreach-object {docker rm $_.split(" ")[-1]}

Example 3:

The following commands will remove the containers and images created in the last 5 hours in docker.

docker container prune --filter "until=5h"

docker image prune --filter "until=5h"