Docker - Remove container using the docker run --rm command

by
Jeremy Canfield |
Updated: January 26 2025
| Docker articles
By default, when creating a container using the docker run command, the container will not be removed after the container has completed.
The --rm flag can be used to remove the container after it has completed.
In this example, a container is created using the https://hub.docker.com/repository/docker/jeremycanfield/my-hello-world-image image and the container will be removed after it has been completed.
Almost always, this is coupled with the --detach flag to run the container in the background.
[john.doe@docker ~]# docker run --detach --rm --name my-container my-image:latest
Did you find this article helpful?
If so, consider buying me a coffee over at