stop, start and restart act on a container that already exists. None of them create or delete anything.
| Command | Effect |
|---|---|
docker stop web | SIGTERM to PID 1, wait up to 10 s, then SIGKILL |
docker stop -t 2 web | same, with a 2-second timeout |
docker start web | run the container's main process again |
docker restart web | stop, then start |
docker kill web | SIGKILL at once, no grace period |
All of them accept several containers: docker stop web worker.
What docker stop does
docker stop web
│
├─► SIGTERM to PID 1 ──► process exits cleanly ──► Exited (0)
│
└─► no exit after 10 s ──► SIGKILL ──────────────► Exited (137)Servers handle the signal and exit with 0. A process that ignores SIGTERM as PID 1, such as sleep or a plain sh script, is killed after the timeout:
docker run -d --name web nginx:1.27
docker run -d --name worker alpine:3.20 sleep 3600
docker stop web worker
docker ps -a --format 'table {{.Names}}\t{{.Status}}'NAMES STATUS
worker Exited (137) 2 seconds ago
web Exited (0) 12 seconds ago| Exit code | Meaning |
|---|---|
0 | process exited cleanly |
137 | 128 + 9: killed with SIGKILL (stop timeout or kill) |
143 | 128 + 15: ended by SIGTERM without handling it |
-t shortens the wait for processes that will never handle SIGTERM: docker stop -t 2 worker.
What survives a stop
container web
├── image layers (read-only) unchanged
├── writable layer kept across stop / start / restart
├── name, ID, config, logs kept
└── running processes, memory lostA file you created inside the container is still there after docker start. Data in memory, such as an unsaved cache, is not.
start vs run
docker start web | docker run ... nginx:1.27 | |
|---|---|---|
| Container | existing | new |
| Writable layer | kept | empty |
Options (--name, command) | the ones it was created with | the ones you pass now |
You cannot change a container's command or options with start. Remove it and run a new one instead.
Restart policies
docker run --restart POLICY tells Docker to start the container again when its process exits:
| Policy | Restarts when |
|---|---|
no (default) | never |
on-failure | exit code is not 0 |
unless-stopped | it exits for any reason, unless you stopped it with docker stop |
always | it exits for any reason; also after docker stop once the daemon restarts |
A container whose process keeps failing shows Restarting (<code>) in docker ps, and Docker waits longer between attempts (1 s, 2 s, 4 s ...).