Docker Error Guide: 'No such container' — Fix Missing Container References
Fix 'Error response from daemon: No such container' in Docker: check exact names and IDs, list all containers, and handle removed or auto-cleaned containers.
- #docker
- #troubleshooting
- #errors
- #containers
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
A command targeting a container fails because the daemon has no container matching the name or ID you gave it:
Error response from daemon: No such container: myapp
docker exec, docker logs, docker stop, docker inspect, and similar commands resolve their argument to an existing container. If the name is misspelled, the container was removed, or it never existed on this daemon, Docker returns No such container.
Symptoms
docker exec,docker logs, ordocker stopfails withNo such container.docker psdoes not list the container you referenced.- A script that just created and removed a container tries to use it again.
- A short ID prefix no longer uniquely matches any container.
Common Root Causes
- Typo in the name or ID — a single wrong character means no match.
- Container was removed — a
--rmcontainer exited and cleaned itself up, or someone randocker rm. - Container is on a different host or context — you are pointed at the wrong daemon via
docker context. - Container never started — a failed
docker runleft nothing behind. - Using a name that was never assigned — assuming a
--namethat the run command did not set. - Race in scripts — referencing the container before creation completes or after auto-removal.
Diagnostic Workflow
List all containers, running and stopped, to see what actually exists:
docker ps -a
Search specifically for the name you expected:
docker ps -a --filter "name=myapp"
Confirm you are talking to the right daemon; a wrong context is a common surprise:
docker context ls
docker context show
If you expect a container that exited with --rm, check the daemon logs or event stream:
docker events --since 10m --filter "container=myapp"
When you do have a valid reference, verify its state before acting on it:
docker inspect --format '{{.Name}} {{.State.Status}}' <container-id>
Example Root Cause Analysis
A health-check script intermittently failed:
Error response from daemon: No such container: myapp
docker ps -a --filter "name=myapp" returned nothing at the moment of failure. The container had been started with --rm for a one-shot migration:
docker run --rm --name myapp myapp:1.4.2 migrate
Because --rm removes the container as soon as it exits, the follow-up docker logs myapp sometimes ran after the migration finished and the container had already been auto-removed. There was simply no container left to reference. The fix was to drop --rm for jobs whose logs are inspected afterward, then remove the container explicitly once done:
docker run --name myapp myapp:1.4.2 migrate
docker logs myapp
docker rm myapp
The lesson: --rm and post-run inspection do not mix — the container disappears the instant it exits.
Prevention Best Practices
- Verify container existence with
docker ps -a(or a--filter) before commands that assume it. - Avoid
--rmfor containers whose logs or exit state you inspect after they finish. - Confirm the active
docker contextwhen managing remote or multiple daemons. - Use exact, stable names via
--namerather than short ID prefixes that can become ambiguous. - In scripts, guard actions with
docker inspect <name> >/dev/null 2>&1 && ...so a missing container fails gracefully.
Quick Command Reference
docker ps -a # list all containers
docker ps -a --filter "name=myapp" # find by name
docker context ls # check daemons you can target
docker inspect --format '{{.State.Status}}' myapp
docker events --since 10m --filter "container=myapp"
Conclusion
No such container means Docker resolved your name or ID to nothing on the current daemon — usually a typo, a removed --rm container, or the wrong context. List with docker ps -a, confirm the context, and reference containers by exact stable names. Skipping --rm where you need post-run logs eliminates the most common surprise. More runtime fixes live in the Docker stack guides.
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.