How to fix Error response from daemon: Container is not running in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025ยท 541 views

The 'docker exec' command fails because the target container has exited or stopped. This typically happens when containers exit immediately after starting due to missing long-running processes or when you attempt to execute commands in a stopped container.

Quick fix

Fixes Error response from daemon: Container is not running

docker ps -a
  1. Check container status
  2. Start the container before using exec
  3. Check container logs for errors
  4. Run container with interactive terminal
docker โ€” error
docker ps -a
Error response from daemon: Container is not running

What this error means

This error occurs when you attempt to run a command inside a container using `docker exec`, but the target container is not in a running state. The full error message reads: "Error response from daemon: Container <container_id> is not running". The `docker exec` command is designed to execute commands inside containers that are actively running. Unlike virtual machines, Docker containers are ephemeral - they exist only while their main process (PID 1) is running. When that process completes or exits, the container stops. Common scenarios that lead to this error include: containers with shell entrypoints that exit immediately without an interactive terminal, containers whose main application crashed, or simply trying to exec into a container that was previously stopped with `docker stop`.

Typical symptoms

  • 'docker exec' command fails with 'Error response from daemon: Container is not running'
  • Container shows 'Exited' status when running 'docker ps -a'
  • Container starts and immediately stops (shows Up for 0 seconds then Exited)
  • Cannot attach to or interact with the container in any way
  • Container works fine with 'docker run' but exits before you can exec into it

Common causes

  1. Container's main process (CMD/ENTRYPOINT) has completed or exited
  2. Container was explicitly stopped with 'docker stop' command
  3. Container crashed due to application error or unhandled exception
  4. Container was started without interactive/tty flags (-it) for shell-based images
  5. Container has no long-running process to keep it alive (e.g., only runs 'echo' or a script that exits)
  6. Container ran out of resources (memory/CPU) and was killed by the system

How to fix "Error response from daemon: Container is not running"

1Check container status

First, verify the container's current state to understand why it's not running:

bash
docker ps -a

Look for your container in the output. The STATUS column will show either:
- "Up X minutes" (running - this error shouldn't occur)
- "Exited (0)" (completed successfully)
- "Exited (1)" or other non-zero code (crashed or error)
- "Created" (never started)

Note the container ID or name for the next steps.

2Start the container before using exec

If the container has exited, restart it first:

bash
docker start <container_name_or_id>

Then immediately run your exec command:

bash
docker exec -it <container_name_or_id> /bin/bash

Note: If the container exits again immediately after starting, proceed to the next steps to diagnose why.

3Check container logs for errors

If the container keeps exiting, check its logs to understand why:

bash
docker logs <container_name_or_id>

Common issues you might find:
- Application crashes or exceptions
- Missing environment variables or configuration
- File not found errors
- Permission denied errors

The exit code also provides hints:
- Exit code 0: Process completed successfully (not an error, just finished)
- Exit code 1: General error
- Exit code 137: Killed by SIGKILL (often OOM killer)
- Exit code 139: Segmentation fault

4Run container with interactive terminal

For images designed around shells (like ubuntu, alpine, debian), you need to allocate a terminal to keep them running:

bash
# Run with interactive terminal
docker run -it --name my_container <image_name> /bin/bash

# Or run detached with a pseudo-TTY to keep alive
docker run -d -t --name my_container <image_name>

# Now you can exec into it
docker exec -it my_container /bin/bash

The -t flag allocates a pseudo-TTY, and -i keeps STDIN open. Together they keep shell-based containers running.

5Keep container running with a persistent process

If you need a container to stay running for debugging or testing, override the entrypoint with a long-running process:

bash
# Run with tail -f to keep container alive
docker run -d --name my_container <image_name> tail -f /dev/null

# Or use sleep infinity
docker run -d --name my_container <image_name> sleep infinity

# Now exec works
docker exec -it my_container /bin/bash

This is useful when the original CMD/ENTRYPOINT exits too quickly for you to debug.

6Access a stopped container's filesystem

If you only need to inspect files in a stopped container (not run commands), you can commit and create a new container:

bash
# Commit the stopped container to a new image
docker commit <stopped_container_id> debug-image

# Run a new container from that image with a shell
docker run -it debug-image /bin/bash

Alternatively, copy files directly from the stopped container:

bash
docker cp <stopped_container_id>:/path/to/file ./local_destination

Advanced notes

Understanding container lifecycle: Docker containers are fundamentally different from virtual machines. A container runs exactly one process (the entrypoint/CMD), and when that process exits, the container stops. This is by design - containers are meant to be ephemeral and stateless.

Debugging crashed containers: If a container crashes before you can exec into it, use these techniques:

bash
# Run interactively to see output in real-time
docker run -it <image_name>

# Override entrypoint to get a shell before the app runs
docker run -it --entrypoint /bin/bash <image_name>

# Inspect the container's configuration
docker inspect <container_id>

Container restart policies: If you need containers to stay running, configure restart policies:

bash
docker run -d --restart=unless-stopped <image_name>

This won't help if the main process exits cleanly (code 0), but it will restart containers that crash.

Paused containers: Note that containers can also be in a "paused" state (different from stopped). If you see "Container is paused" instead, use:

bash
docker unpause <container_name_or_id>

Using docker run instead: For one-off commands in images where you don't need a persistent container, consider using docker run with --rm instead of creating a container and exec-ing into it:

bash
docker run --rm -it <image_name> /bin/bash

Frequently asked questions

What does "Error response from daemon: Container is not running" mean?
This error occurs when you attempt to run a command inside a container using docker exec, but the target container is not in a running state. The full error message reads: "Error response from daemon: Container <container_id> is not running". The docker exec command is designed to execute commands inside containers that are actively running.
How do I fix "Error response from daemon: Container is not running"?
The 'docker exec' command fails because the target container has exited or stopped. This typically happens when containers exit immediately after starting due to missing long-running processes or when you attempt to execute commands in a stopped container.
What causes "Error response from daemon: Container is not running"?
Container's main process (CMD/ENTRYPOINT) has completed or exited Container was explicitly stopped with 'docker stop' command Container crashed due to application error or unhandled exception
Is the "Error response from daemon: Container is not running" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading