---
title: "Let the main process receive stop signals · Agent Wranglers"
url: https://agentwranglers.se/playbook/operations/containers/container-signals
updated: 2026-10-20
licence: "All rights reserved"
---

# Let the main process receive stop signals

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Containers](https://agentwranglers.se/playbook/operations/containers)
- Rule: Start the app in exec form, so it receives the stop signal itself. Add a small init process that forwards signals and reaps child processes.
- How: Write `CMD ["node", "server.js"]`, not `CMD node server.js`, which starts a shell that swallows signals. Run with `--init`, or `init: true` in Compose, or install tini as the entry point. The app then [shuts down cleanly](https://agentwranglers.se/playbook/operations/running-the-service/graceful-shutdown) instead of being killed after the timeout.
- Check: `docker stop` on a running container finishes before its kill timeout, which is 10 seconds by default. `docker inspect --format '{{.State.ExitCode}}'` then shows 0, not 137, and the app logs its shutdown message.

Example:

```dockerfile
# Bad: a shell becomes process 1 and ignores SIGTERM
CMD node server.js

# Good: the app gets the signal
CMD ["node", "server.js"]
```

```yaml
services:
  web:
    init: true
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers operations playbook: https://agentwranglers.se/playbook/operations/containers/container-signals`.

- Previous: [Pass build secrets as mounts instead of layers](https://agentwranglers.se/playbook/operations/containers/build-secrets)
- Next: [Make the container file system read-only](https://agentwranglers.se/playbook/operations/containers/read-only-containers)
- [Containers](https://agentwranglers.se/playbook/operations/containers)
