How to remove stopped and unused container in Docker.

Date: 06-02-2021

Step 01: List all Docker containers using the command.
# docker ps -a
# docker container ls -a

Step 02: Enter the below command to stop the specific container.
# docker container stop [Container_id]
Note: [Container_id] – Numeric ID of the container from your list.
Use below command to stop all running container.
# docker container stop $(docker container ls -a)

Step 03: Use the below command to remove a stopped container.
# docker container rm [Container_id]
To remove all stopped and unused containers:
# docker container rm $(docker container ls -a)
# docker system prune

Thank you!

Leave a Reply