How to fix Error response from daemon: Container is not running in Docker
This error occurs when attempting to execute commands on a stopped Docker container. The container exists but is not in a running state, preventing operations like exec, logs, or attach from working.
Quick fix
Fixes Error response from daemon: Container is not running
docker ps -a- Check container status and exit code
- Inspect container logs for errors
- Start the stopped container
- Run container with interactive mode for debugging
docker ps -aError response from daemon: Container is not running
What this error means
The "Container is not running" error from the Docker daemon indicates that you're attempting to perform an operation on a container that exists but is currently stopped. Unlike traditional virtual machines, Docker containers are designed to run a single process or application. When that process exits or is stopped, the container stops as well. This error commonly appears when using commands like `docker exec`, `docker attach`, or `docker logs` on containers that have exited. The container's state is preserved on disk, but it's not actively executing any processes. Understanding container lifecycle is key: containers transition between states (Created, Running, Paused, Stopped, Exited) based on the process they're running. A stopped container can be restarted, but operations requiring an active process will fail with this error.
Typical symptoms
- Docker exec commands fail with 'Container is not running' error
- Container appears in docker ps -a but not in docker ps
- Attach or logs commands return daemon errors
- Container shows 'Exited' status with non-zero exit code
- Application immediately stops after docker run or docker start
- CI/CD pipelines fail when trying to interact with containers
Common causes
- Container's main process exited or completed successfully
- Application inside container crashed due to errors
- Container was manually stopped with docker stop
- Entry command or script completed and had no long-running process
- Host system restarted without restart policy configured
- Missing dependencies or incorrect configuration prevented startup
- Resource constraints (memory, CPU) caused the container to stop
How to fix "Error response from daemon: Container is not running"
First, list all containers including stopped ones to identify your container:
docker ps -aLook for the STATUS column. If it shows "Exited (0)", the process completed normally. A non-zero exit code indicates an error. Note the container ID or name.
Check the logs to understand why the container stopped:
docker logs <container_id>Look for error messages, stack traces, or application crashes that caused the exit. This often reveals missing environment variables, connection failures, or startup errors.
If the container simply needs to be restarted:
docker start <container_id>Then verify it's running:
docker ps | grep <container_id>If it starts successfully, you can now run exec commands or access logs.
If the container exits immediately, run it interactively to debug:
docker run -it <image_name> /bin/bashOr override the entrypoint to get a shell:
docker run -it --entrypoint /bin/sh <image_name>This allows you to explore the container environment and test commands manually.
Docker containers need a foreground process to stay running. If your CMD or ENTRYPOINT exits, the container stops. Common fixes:
Bad (exits immediately):
CMD echo "Hello"Good (runs indefinitely):
CMD ["nginx", "-g", "daemon off;"]
# or
CMD ["node", "server.js"]
# or for debugging
CMD ["tail", "-f", "/dev/null"]Ensure your Dockerfile's CMD or ENTRYPOINT starts a long-running process.
To automatically restart containers after host reboots or crashes:
docker run -d --restart unless-stopped <image_name>Or update an existing container:
docker update --restart unless-stopped <container_id>Restart policies: no (default), on-failure, always, unless-stopped.
Advanced notes
Container Lifecycle Management:
Containers are not VMs. They run a single process tree defined by CMD/ENTRYPOINT. When that process exits (PID 1), the container stops. Use docker inspect to see detailed state information and exit codes.
Debugging Exited Containers:
Use docker inspect <container_id> | jq '.[0].State' to see exit code, error message, and timestamps. Exit codes follow Unix conventions (0 = success, 1 = general error, 126 = command cannot execute, 127 = command not found, 137 = SIGKILL, 143 = SIGTERM).
Docker Compose Considerations:
In Docker Compose, use restart: unless-stopped or restart: always in service definitions. Combine with health checks to ensure containers are not just running, but functional.
Common Pitfall with Shell Scripts:
If your entrypoint is a shell script, ensure it doesn't exit prematurely. Use exec to replace the shell process with your application: exec node server.js instead of node server.js, so signals reach your app directly.
CI/CD Best Practices:
In CI environments (GitHub Actions, GitLab CI), containers may exit if the build platform doesn't match. Use docker buildx with --platform linux/amd64 for cross-platform builds.
Frequently asked questions
- What does "Error response from daemon: Container is not running" mean?
- The "Container is not running" error from the Docker daemon indicates that you're attempting to perform an operation on a container that exists but is currently stopped. Unlike traditional virtual machines, Docker containers are designed to run a single process or application. When that process exits or is stopped, the container stops as well.
- How do I fix "Error response from daemon: Container is not running"?
- This error occurs when attempting to execute commands on a stopped Docker container. The container exists but is not in a running state, preventing operations like exec, logs, or attach from working.
- What causes "Error response from daemon: Container is not running"?
- Container's main process exited or completed successfully Application inside container crashed due to errors Container was manually stopped with docker stop
- 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
- ๐Docker Official Documentation
- ๐ฌContainer is not running - Stack Overflow(Stack Overflow)
- ๐Docker Start Documentation(Official Docs)
- ๐
- ๐ฌDocker Community Forums(Stack Overflow)