Docker Container Prune

This command removes all stopped containers.

Syntax

docker container prune CONTAINER [CONTAINER...]

Options

--force, -f: Do not prompt for confirmation

Run docker container prune, which should remove all the unused containers that exit.

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS            NAMES
cb4a3f67a222   nginx     "/docker-entrypoint.…"   9 minutes ago   Up 9 minutes   80/tcp           eloquent_chatelet

learning-ocean:~ gaurav$ docker container ls -a
CONTAINER ID   IMAGE         COMMAND                   CREATED          STATUS            PORTS           NAMES
cb4a3f67a222   nginx        "/docker-entrypoint.…"     9 minutes ago    Up 9 minutes      80/tcp          eloquent_chatelet
89d34da28b5d   nginx        "/docker-entrypoint.…"     28 minutes ago   Exited (137) 28 minutes ago       happy_cori
ebc16ec59b23   nginx        "/docker-entrypoint.…"     40 minutes ago   Exited (0) 28 minutes ago         suspicious_cannon

learning-ocean:~ gaurav$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
89d34da28b5d4a4e15a6262cb6414106527a377eeeebdcf7aa4a7e8ef766260b
ebc16ec59b23ef8cb2141ff21e926832623b4fcf6ed603d6e905d99576f378ca

Total reclaimed space: 49.51MB
learning-ocean:~ gaurav$