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

DockerBEGINNERLOWUpdated Dec 6, 2025ยท 241 views

Docker cannot restart a stopped container because the restart command only works on running containers. Use docker start instead, or check why the container exited and address the underlying issue.

Quick fix

Fixes Error response from daemon: Cannot restart container: Container is not running

docker ps -a | grep <container_name_or_id>
  1. Check the container's current status
  2. Use docker start instead of docker restart
  3. Check container logs for exit reasons
  4. Inspect the container for detailed state information
docker โ€” error
docker ps -a | grep <container_name_or_id>
Error response from daemon: Cannot restart container: Container is not running

What this error means

This error occurs when you attempt to use `docker restart` on a container that has already exited or was never started. The Docker restart command is designed to stop a running container and then start it again, but it cannot operate on containers that are not currently running. When Docker reports "Cannot restart container: Container is not running," it means the container you're targeting is in an exited state. This can happen for various reasons: the container's main process completed successfully, the process crashed, or the container was explicitly stopped and never started again. The key distinction here is between `docker restart` and `docker start`. The restart command performs a stop-then-start sequence, which requires the container to be running first. The start command, on the other hand, can bring up a stopped container from its exited state.

Typical symptoms

  • Running 'docker restart <container>' fails with 'Container is not running' error
  • Container shows 'Exited' status when running 'docker ps -a'
  • Automation scripts that use 'docker restart' fail unexpectedly
  • Container restart policies don't seem to be working as expected
  • CI/CD pipelines fail when trying to restart containers after builds

Common causes

  1. Using 'docker restart' on a container that has already exited
  2. Container's main process completed or crashed, leaving it in exited state
  3. Container was created but never started with 'docker start'
  4. Container was stopped with 'docker stop' and restart was called instead of start
  5. Incorrect restart policy configuration preventing automatic restarts
  6. Container's entrypoint or command exited with an error

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

1Check the container's current status

First, verify the container's state to understand why the restart failed:

bash
docker ps -a | grep <container_name_or_id>

Look at the STATUS column. If it shows "Exited (0)" the container completed normally. If it shows "Exited (1)" or another non-zero code, the container crashed. The "Exited" status confirms why docker restart won't work.

2Use docker start instead of docker restart

For containers in an exited state, use docker start to bring them back up:

bash
docker start <container_name_or_id>

This will start the container using the same configuration it was created with. If you need to see the output:

bash
docker start -a <container_name_or_id>

The -a flag attaches STDOUT/STDERR so you can see what's happening.

3Check container logs for exit reasons

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

bash
docker logs <container_name_or_id>

For more detailed output with timestamps:

bash
docker logs --tail 50 --timestamps <container_name_or_id>

The logs will show you what the application inside the container printed before it exited, which often reveals the root cause.

4Inspect the container for detailed state information

Get comprehensive information about the container's state:

bash
docker inspect <container_name_or_id> --format='{{.State.Status}} - ExitCode: {{.State.ExitCode}}'

Or view the full state section:

bash
docker inspect <container_name_or_id> | grep -A 20 '"State"'

This shows the exact exit code, when it stopped, and why. Common exit codes: 0 (success), 1 (general error), 137 (killed by SIGKILL), 143 (killed by SIGTERM).

5Configure a restart policy for automatic recovery

To prevent this issue in the future, set a restart policy when running containers:

bash
# Always restart unless explicitly stopped
docker run --restart=unless-stopped <image>

# Restart only on failure (non-zero exit code)
docker run --restart=on-failure <image>

# Always restart, even after Docker daemon restarts
docker run --restart=always <image>

For existing containers, update the restart policy:

bash
docker update --restart=unless-stopped <container_name_or_id>

Note: The restart policy only takes effect after a successful start. You'll still need to use docker start first.

6Recreate the container if configuration needs changes

If you need to modify the container's configuration or it won't start properly, recreate it:

bash
# Remove the old container
docker rm <container_name_or_id>

# Create and run a new one with proper settings
docker run -d --name <container_name> --restart=unless-stopped <image>

For docker-compose projects:

bash
docker-compose up -d --force-recreate <service_name>

This ensures you have a fresh container with the correct configuration.

Advanced notes

Understanding restart vs start: The docker restart command is equivalent to running docker stop followed by docker start. Since docker stop requires a running container, the entire restart operation fails if the container is already stopped. This is by design - restart is meant for gracefully cycling running services.

Restart policies explained:
- no: Never automatically restart (default)
- on-failure[:max-retries]: Restart only when the container exits with a non-zero code
- always: Always restart regardless of exit code; also starts on daemon startup
- unless-stopped: Like always, but won't start if it was manually stopped before daemon restart

Docker Compose considerations: In docker-compose.yml, use the restart key:

yaml
services:
  web:
    image: nginx
    restart: unless-stopped

The docker-compose restart command works differently - it sends the restart signal to all services, but individual containers still need to be running.

Systemd integration: If Docker itself isn't starting on boot, containers won't auto-start even with restart policies:

bash
# Enable Docker to start on boot
sudo systemctl enable docker.service

# Check if Docker socket is the issue
sudo systemctl enable docker.socket

Exit code analysis: When troubleshooting repeated exits:
- Exit code 0: Process completed normally (may indicate CMD finished rather than crashed)
- Exit code 1: General application error
- Exit code 125: Docker daemon error
- Exit code 126: Permission problem or command not executable
- Exit code 127: Command not found
- Exit code 137: Container received SIGKILL (OOM killer or manual kill)
- Exit code 143: Container received SIGTERM (graceful shutdown)
- Exit code 255: Exit status out of range

Frequently asked questions

What does "Error response from daemon: Cannot restart container: Container is not" mean?
This error occurs when you attempt to use docker restart on a container that has already exited or was never started. The Docker restart command is designed to stop a running container and then start it again, but it cannot operate on containers that are not currently running. When Docker reports "Cannot restart container: Container is not running," it means the container you're targeting is in an exited state.
How do I fix "Error response from daemon: Cannot restart container: Container is not"?
Docker cannot restart a stopped container because the restart command only works on running containers. Use docker start instead, or check why the container exited and address the underlying issue.
What causes "Error response from daemon: Cannot restart container: Container is not"?
Using 'docker restart' on a container that has already exited Container's main process completed or crashed, leaving it in exited state Container was created but never started with 'docker start'
Is the "Error response from daemon: Cannot restart container: Container is not" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading