How to remove a Docker container

Removing a Docker container can easily be done by following these steps:

  • Use the docker ps command with the -a flag to locate the name or ID of the container(s) you want to remove:
docker ps -a
  • Run the following command and replace <ID> by the ID of the container that you want to remove:
docker rm <ID>
  • Multiple containers can also be removed with the command above:
docker rm <ID1> <ID2>

You can also automatically remove a container when it exits. This is useful if you know, while creating a container, that you will not need it afterward. The ​following command will run the container and automatically remove it upon exit:

docker run --rm image_name
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved