Ch. 13 · Docker

Docker Process Signals and Graceful Shutdown

Docker Process Signals and Graceful Shutdown. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readbeginnerupdated Oct 3, 2026

The container’s main process must handle termination and reap child processes appropriately. Wrapper scripts should forward control deliberately.

Before you start

You should understand the difference between an image, a running container and the host. Record where a file, process or network endpoint actually lives before diagnosing a problem. Commands illustrate local experiments; adapt image names and paths to a disposable development environment.

The practical goal is to reason through this situation: An exec-based startup lets the application receive termination signals directly. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Locate the main process

Find whether PID 1 is the application or a shell wrapper.

Step 2: Forward execution deliberately

After setup, exec the application when the wrapper no longer needs to supervise it.

Step 3: Handle child ownership

Use an appropriate init strategy when orphan reaping and forwarding are required.

Worked scenario

An exec-based startup lets the application receive termination signals directly.

#!/bin/sh
set -e
# perform required setup here
exec "$@"
Terminal

The supplied executable replaces the wrapper process and can receive termination directly. The application still needs its own graceful-shutdown handler; exec does not implement request draining.

Common mistake

A shell wrapper can prevent the application from receiving the intended signal.

Verify the behavior

Stop the container during an active request and verify signal reception and bounded shutdown.

Interview exercise

Write a reliable startup script.

Answer and reasoning

Complete setup, then exec the application, or use a suitable init strategy when child-process management requires it.

Continue learning

Compare the scenario with the Docker interview questions and test your understanding with the Docker MCQs. For terminology and implementation details, consult the reference material.

More in Docker

read ✓Docker · mid

Docker BuildKit and Cache Mounts

Speed up image builds with BuildKit cache mounts, multi-stage builds and dependency-first layer ordering.

~2 min readread →
read ✓Docker · mid

Docker Compose Profiles

Start only the services you need with Compose profiles, and keep the default set small for focused local development.

~2 min readread →
esc