How to remove a Docker container
Removing a Docker container can easily be done by following these steps:
- Use the
docker pscommand with the-aflag 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
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved