Deleting a Docker container removes it completely from your system
A Docker container is a running instance of an image — think of it as a temporary copy of a program that Docker created when you started it. When you delete a container, Docker removes that instance entirely, along with any files or changes you made inside it. The original image stays on your computer, so you can create new containers from it whenever you want.
You delete containers when you no longer need them, when they are taking up disk space, or when you want to start fresh with a new one. Unlike stopping a container (which pauses it), deleting removes it permanently. This is safe to do because the container's data is temporary by design — anything you want to keep should be saved outside the container first.
Key Takeaways
- Use docker rm followed by the container name or ID to delete a single container that is not currently running.
- Stop a running container with docker stop before you delete it, or use the -f flag to force deletion without stopping first.
- Find the container name or ID by running docker ps -a, which lists all containers on your system.
- Delete multiple containers at once by listing their names or IDs separated by spaces, or use docker container prune to remove all stopped containers in one command.
- Deleting a container does not delete the image it came from, so you can create new containers from that image later.
Find the container you want to delete
Before you can delete a container, you need to know its name or ID. Open your terminal or command prompt and run this command:
docker ps -a
This shows every container on your system, including ones that are currently running and ones that have stopped. You will see columns for container ID, image name, command, creation time, status, ports, and the container name. The container name is usually the easiest way to identify which one you want to delete — it is the rightmost column and is often something like web-server or database-1.
If you only want to see containers that are currently running, use docker ps without the -a flag. Stopped containers will not appear in that list.
Stop the container if it is still running
If the container is currently running, you have two choices: stop it first, or force-delete it. Stopping first is the cleaner approach and gives the container a chance to shut down gracefully.
To stop a running container, run:
docker stop container-name
Replace container-name with the actual name from the docker ps -a output. Docker will wait a few seconds for the container to shut down on its own, then move on. Once the container has stopped, you can delete it using the steps in the next section.
If you want to skip the stop step and delete when ready, you can use the -f (force) flag when you delete, which is covered below.
Delete a single container
Once the container is stopped, delete it with:
docker rm container-name
Replace container-name with the name or ID from your docker ps -a list. Docker will remove the container and return to the command prompt with no message — that silence means it worked.
If the container is still running and you want to delete it without stopping it first, add the -f flag:
docker rm -f container-name
The -f flag forces Docker to kill the container when ready and then delete it. This is faster but does not give the container a chance to clean up gracefully, so use it only when you do not care about that.
Delete multiple containers at once
If you want to delete several containers, you can list them all in one command. Separate each container name or ID with a space:
docker rm container-1 container-2 container-3
If any of those containers are still running, add the -f flag to force-delete them all:
docker rm -f container-1 container-2 container-3
For a faster way to clean up, use docker container prune. This command deletes every stopped container on your system in one go:
docker container prune
Docker will ask you to confirm before it deletes anything. This is useful when you have accumulated many old containers and want to free up space without listing each one individually. It only removes stopped containers — running containers are left alone.
Verify the container is deleted
After you delete a container, run docker ps -a again to confirm it is gone. The container should no longer appear in the list. If you see an error message instead, the deletion may have failed — this usually happens if Docker does not have permission to delete the container, or if the container name was misspelled.
Remember that deleting a container does not delete the image it came from. If you want to remove the image as well, use docker rmi image-name in a separate command. You can always create a new container from the image later if you need to.
Frequently Asked Questions
What happens to my data when I delete a container?
Any files or changes inside the container are deleted permanently. If you need to save data, copy it out of the container before you delete it using docker cp, or use Docker volumes to store data outside the container so it survives deletion.
Can I delete a container that is currently running?
Yes, but you should stop it first with docker stop to let it shut down cleanly. If you want to delete it without stopping, use docker rm -f, which forces the deletion when ready.
Does deleting a container delete the image too?
No. Deleting a container only removes that instance. The image stays on your system, and you can create new containers from it anytime. To delete the image itself, use docker rmi image-name in a separate command.
How do I delete a container by ID instead of by name?
Use the container ID from the docker ps -a output the same way you would use the name: docker rm container-id. You do not need to type the full ID — the first 12 characters are usually enough for Docker to identify it.
What does the error "container is running" mean?
Docker is telling you the container is still active and cannot be deleted without stopping it first. Run docker stop container-name, then try docker rm container-name again. Or use docker rm -f to skip the stop step.