Error response from daemon: container ... is not running from
docker exec means the container exists but its main process has already
ended. exec starts a second process inside a running container, so start
the container first, or find out why it exited.
Check with docker ps -a: an Exited status confirms it. Run
docker start <name> and try again, but if the container exits straight
away its command finished or crashed, and docker logs <name> tells you
which.
The error
PS> docker exec fix8-cli-e echo hi
Error response from daemon: container 6bb3c1ea8bd4b73a5f7cfb4a3d221c334fc10385874a92e3322754b466a667d6 is not running
A name that does not exist at all gives a different message:
PS> docker exec fix8-cli-nope echo hi
Error response from daemon: No such container: fix8-cli-nope
Why it happens
A container lives exactly as long as its main process, the command in
CMD or the one you passed to docker run. When that process
ends, the container moves to Exited but stays on disk with its name and ID.
docker exec does not start containers; it joins a process to one that is
already running, so on an exited container it has nothing to join.
The usual reasons the main process ended: the command was short-lived (a script, an
echo, a sleep that ran out), the application crashed on
startup, or someone stopped the container. The ubuntu:24.04 image runs
/bin/bash by default, which exits at once without a terminal, so
docker run -d ubuntu:24.04 followed by docker exec two seconds
later failed the same way in the test.
The fix
PS> docker ps -a --filter name=fix8-cli-e --format '{{.Names}} {{.Status}}'
fix8-cli-e Exited (0) 3 seconds ago
PS> docker run -d --name fix8-cli-f alpine sleep infinity
0813c8bf8516e7b877d4fc1734a82e4ad25c95031c7bced2f218b07fa2e8701b
PS> docker exec fix8-cli-f echo hi
hi
The test container ran sleep 2, so it was gone four seconds later. Giving
it a command that keeps running, here sleep infinity, keeps it alive for
exec. For a real service the main process should be the server itself; if
it exits, read docker logs for the crash rather than keeping the container
alive artificially. If you only need a one-off command, docker run --rm image
command does it without exec.
How it was reproduced
Docker Desktop on Windows 11, client and engine 29.9.2, Windows PowerShell 5.1, the
cached alpine:latest image. docker run -d --name fix8-cli-e alpine
sleep 2, a wait of four seconds, then docker exec gave the message
above; a container started with sleep infinity answered the same
exec. The names in the output are the test's own.
Frequently asked
- Why does my Docker container exit immediately?
- A container runs only as long as its main command. A shell with no terminal, a short script or an application that crashes on startup all end it at once. Check docker logs and docker ps -a for the exit code.
- Can docker exec start a stopped container?
- No. docker exec only adds a process to a running container. Use docker start first, or docker run --rm with the command for a one-off task.
- How do I keep a container running so I can exec into it?
- Give it a long-running main process, for example docker run -d --name box alpine sleep infinity. For an application container, fix the crash that stops it instead.
More decoded errors in the Fixes category. If
exec fails with a TTY message instead, see
the input
device is not a TTY.