How to fix Error: No such container: mycontainer in Docker

DockerBEGINNERLOWUpdated Dec 1, 2025ยท 532 views

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.

Quick fix

Fixes Error: No such container: mycontainer

docker ps -a
  1. List all containers to verify existence
  2. Copy the exact container name or ID
  3. Create containers with explicit names
  4. Understand image vs container names
docker โ€” error
docker ps -a
Error: No such container: mycontainer

What this error means

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.

Typical symptoms

  • Commands like 'docker start', 'docker stop', or 'docker exec' fail with 'No such container' error
  • Container appears to be missing from 'docker ps' output
  • CI/CD pipeline fails when trying to reference a previously created container
  • Docker Compose commands fail with container not found messages
  • Error messages show a container ID or name that you're certain you created

Common causes

  1. Using an image name instead of a container name in Docker commands
  2. Container was created with the '--rm' flag and automatically removed after exit
  3. Typo in the container name or ID when running commands
  4. Container was manually removed with 'docker rm' or 'docker container prune'
  5. Container exited and you're only viewing running containers with 'docker ps' (need 'docker ps -a')
  6. Using shortened container ID that matches multiple containers or none
  7. Docker daemon was restarted and container references became stale
  8. Referring to a container in a different Docker context (when using remote Docker hosts)

How to fix "Error: No such container: mycontainer"

1List all containers to verify existence

First, check if your container exists at all. Use the '-a' flag to see both running and stopped containers:

bash
docker ps -a

Look 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.

2Copy the exact container name or ID

To avoid typos, copy the container identifier directly from the 'docker ps -a' output:

bash
# Get full container ID (no truncation)
docker ps -a --no-trunc

# Filter by partial name if you know it
docker ps -a | grep myapp

Copy 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.

3Create containers with explicit names

If your container doesn't exist, create it with a memorable name using the '--name' flag:

bash
docker run --name mycontainer -d nginx:latest

This is much better than letting Docker assign random names like 'hungry_tesla' or 'clever_banach'. You can then reference it reliably:

bash
docker stop mycontainer
docker start mycontainer
docker exec -it mycontainer bash
4Understand image vs container names

A common mistake is confusing image names with container names:

bash
# 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 name

Always use '--name' when creating containers to avoid this confusion.

5Check if container was auto-removed

Containers launched with '--rm' are automatically deleted after they exit:

bash
# 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 container

If you need to keep the container for debugging or restart later, don't use the '--rm' flag. Remove it manually when you're done:

bash
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 done
6Verify Docker context for remote hosts

If you're using Docker contexts to manage remote Docker hosts, ensure you're connected to the correct context:

bash
# 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 -a

Containers exist on specific Docker hosts, so switching contexts changes which containers you can see.

Advanced notes

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'.

Frequently asked questions

What does "Error: No such container: mycontainer" mean?
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'.
How do I fix "Error: No such container: mycontainer"?
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.
What causes "Error: No such container: mycontainer"?
Using an image name instead of a container name in Docker commands Container was created with the '--rm' flag and automatically removed after exit Typo in the container name or ID when running commands
Is the "Error: No such container: mycontainer" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading