The 'No such container' error occurs when Docker cannot find a container you're trying to interact with. This typically happens when using an incorrect container name or ID, or when the container has already been removed.
The "No such container" error is Docker's way of telling you that it cannot locate a container matching the name or ID you specified in your command. This error appears when you attempt to start, stop, inspect, remove, or execute commands in a container that doesn't exist in Docker's container registry. Docker maintains a registry of all containers (both running and stopped) that you can view with 'docker ps -a'. When you reference a container by name or ID, Docker searches this registry. If no match is found, you'll receive this error. This is one of the most common Docker errors for beginners because it often stems from confusion between image names and container names, or from assuming a container still exists after it has been automatically removed.
First, check if your container exists at all. Use the '-a' flag to see both running and stopped containers:
docker ps -aLook through the output for your container. The NAMES column shows the container name, and CONTAINER ID shows the ID. If you don't see your container, it has been removed and needs to be recreated.
To avoid typos, copy the container identifier directly from the 'docker ps -a' output:
# Get full container ID (no truncation)
docker ps -a --no-trunc
# Filter by partial name if you know it
docker ps -a | grep myappCopy the value from the NAMES or CONTAINER ID column and paste it into your command. Container IDs can be shortened to the first few characters (e.g., 'a1b2c3') as long as they're unique.
If your container doesn't exist, create it with a memorable name using the '--name' flag:
docker run --name mycontainer -d nginx:latestThis is much better than letting Docker assign random names like 'hungry_tesla' or 'clever_banach'. You can then reference it reliably:
docker stop mycontainer
docker start mycontainer
docker exec -it mycontainer bashA common mistake is confusing image names with container names:
# This creates a container from the 'nginx' IMAGE
docker run nginx
# 'nginx' is the IMAGE name, not the container name
# Docker assigns a random container name like 'eloquent_keller'
# This will FAIL - 'nginx' is not a container name
docker stop nginx # Error: No such container: nginx
# You need to use the actual container name or ID
docker ps -a # Find the real name/ID
docker stop eloquent_keller # Use the actual container nameAlways use '--name' when creating containers to avoid this confusion.
Containers launched with '--rm' are automatically deleted after they exit:
# This container will be removed after it stops
docker run --rm --name tempcontainer busybox echo "Hello"
# After the command completes, the container is gone
docker start tempcontainer # Error: No such containerIf you need to keep the container for debugging or restart later, don't use the '--rm' flag. Remove it manually when you're done:
docker run --name mycontainer busybox echo "Hello"
docker ps -a # Container still exists in 'Exited' state
docker start mycontainer # Works fine
docker rm mycontainer # Remove when doneIf you're using Docker contexts to manage remote Docker hosts, ensure you're connected to the correct context:
# List available contexts
docker context ls
# Check current context
docker context show
# Switch to the correct context
docker context use my-remote-host
# Now list containers in that context
docker ps -aContainers exist on specific Docker hosts, so switching contexts changes which containers you can see.
Docker Compose behavior: When using Docker Compose, container names are automatically prefixed with the project name and service name (e.g., 'myproject_web_1'). You can find the actual name with 'docker-compose ps' or by using service names directly in compose commands ('docker-compose exec web bash').
Container ID uniqueness: You can use shortened container IDs (first 3-12 characters) as long as they're unique among all containers. If multiple containers start with the same characters, you'll need to provide more characters to disambiguate.
Stopped vs removed: A stopped container ('docker stop') still exists and can be restarted. A removed container ('docker rm') is permanently deleted. Use 'docker ps -a' to see stopped containers, and 'docker container prune' to clean up all stopped containers.
Debugging rapid exits: If a container exits immediately after creation, it may be removed before you can interact with it. Use 'docker logs <container_id>' on stopped containers to see why they exited, or add '-it' flags to keep the container interactive: 'docker run -it myimage bash'.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec