Stop and remove a container
Destructive
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Gracefully stops a running container and deletes it, discarding its writable layer. The image and any named volumes it used are kept.
dockerstopremovecontainers
Confirmation required
This recipe is destructive and requires confirmation — confirm you understand the impact before running any command below.
Parameters
Name or ID of the container to stop and remove.
Commands
Review the container's image, mounts, and state before deleting it
docker inspect <container>Send SIGTERM and wait for the process to shut down cleanly
docker stop <container>Delete the container and its writable layer permanently
docker rm <container>Verification
docker ps --all --filter name=<container>The container no longer appears in the list.
Undo
Not undoable
The container's writable layer — any files created or modified inside it outside of volumes — is permanently deleted. A new container can be started from the same image, but that lost state cannot be recovered.
Pitfalls
- Data in bind mounts and named volumes survives; everything else written inside the container is lost.
- docker stop waits 10 seconds before force-killing; add --timeout for slow-shutdown services.
- Anonymous volumes are left behind unless docker rm --volumes is used; they then linger until pruned.