How to fix Error response from daemon: cannot stop container: container is not running in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025· 174 views

This error occurs when you attempt to stop or kill a Docker container that has already exited. It's a harmless informational message indicating the container is not in a running state and doesn't require stopping.

Quick fix

Fixes Error response from daemon: cannot stop container: container is not running

docker ps
  1. Check the current container status
  2. Remove the stopped container instead
  3. Stop only running containers in scripts
  4. Clean up all stopped containers
docker — error
docker ps
Error response from daemon: cannot stop container: container is not running

What this error means

This error message appears when you run `docker stop` or `docker kill` on a container that is already in a stopped or exited state. Docker containers can only be stopped when they're actually running. When a container has already exited (either normally or due to an error), attempting to stop it again will trigger this error. The error is typically not a problem—it's simply Docker's way of informing you that the requested operation (stopping a running container) doesn't apply to the current state of the container. The container might have stopped on its own, been stopped by another process, or crashed before you attempted to stop it. Understanding container states is key: a container can be in states like "running," "exited," "paused," or "restarting." The stop and kill commands only work on containers in the "running" state.

Typical symptoms

  • Running docker stop on a container returns 'container is not running' error
  • docker ps shows the container but docker ps -a shows it with 'Exited' status
  • Automation scripts fail when attempting to stop containers that are already stopped
  • CI/CD pipelines report errors during container cleanup phases

Common causes

  1. Attempting to stop a container that has already exited or been stopped
  2. Using docker ps -a to list all containers (including stopped ones) then piping to docker stop
  3. Container crashed or terminated before the stop command was issued
  4. Cleanup scripts that don't check container state before attempting to stop
  5. Systemd service or orchestrator already stopped the container
  6. Multiple users or processes attempting to manage the same container

How to fix "Error response from daemon: cannot stop container: container is not running"

1Check the current container status

First, verify whether the container is actually running:

bash
docker ps

This shows only running containers. If your container doesn't appear here, it's not running.

To see all containers including stopped ones:

bash
docker ps -a

Look for your container in the list. The STATUS column will show something like "Exited (0) 2 minutes ago" if it's stopped.

2Remove the stopped container instead

If the container is already stopped and you want to remove it entirely:

bash
docker rm <container_id_or_name>

If the container is somehow stuck or you want to force removal:

bash
docker rm -f <container_id_or_name>

The -f flag will force removal even if the container is in an unusual state.

3Stop only running containers in scripts

When writing automation scripts, filter for running containers only:

bash
# Stop all running containers (safe approach)
docker stop $(docker ps -q)

The -q flag lists only IDs, and docker ps without -a shows only running containers.

For conditional stopping in scripts:

bash
# Check if container is running before stopping
if [ "$(docker inspect -f '{{.State.Running}}' container_name 2>/dev/null)" == "true" ]; then
  docker stop container_name
else
  echo "Container is not running, skipping stop"
fi
4Clean up all stopped containers

To remove all stopped containers at once:

bash
docker container prune

Docker will ask for confirmation before removing stopped containers. To skip confirmation:

bash
docker container prune -f

This is useful for regular maintenance and freeing up disk space.

Advanced notes

Idempotent Operations: The docker stop command is designed to be idempotent in most use cases. If you need truly idempotent behavior in scripts (no error on already-stopped containers), use conditional checks or redirect stderr.

Docker Compose: When using Docker Compose, docker-compose down handles both stopping and removing containers gracefully, regardless of their current state. This is often safer for multi-container applications.

Container State Machine: Docker containers follow a state machine: created → running → paused/stopped → removed. Understanding this flow helps prevent these errors. You can inspect detailed state with docker inspect <container_id> | jq '.State'.

Systemd Integration: If you've configured containers to run as systemd services, stopping via docker stop might cause the service to restart the container immediately. Always stop the systemd service first: systemctl stop docker-<container_name>.service.

Race Conditions: In distributed systems or when multiple administrators manage the same Docker host, race conditions can occur where a container is stopped between your status check and stop command. Always handle this error gracefully in production scripts.

Frequently asked questions

What does "Error response from daemon: cannot stop container: container is not ru" mean?
This error message appears when you run docker stop or docker kill on a container that is already in a stopped or exited state. Docker containers can only be stopped when they're actually running. When a container has already exited (either normally or due to an error), attempting to stop it again will trigger this error.
How do I fix "Error response from daemon: cannot stop container: container is not ru"?
This error occurs when you attempt to stop or kill a Docker container that has already exited. It's a harmless informational message indicating the container is not in a running state and doesn't require stopping.
What causes "Error response from daemon: cannot stop container: container is not ru"?
Attempting to stop a container that has already exited or been stopped Using docker ps -a to list all containers (including stopped ones) then piping to docker stop Container crashed or terminated before the stop command was issued
Is the "Error response from daemon: cannot stop container: container is not ru" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading