Graceful container upgrades
Distinguish a reload from a container replacement
A bind-mounted file can change without Nginx re-reading it. A reload asks the same master to validate new settings and replace workers gracefully; a container replacement starts a new process and runtime filesystem. Single-file bind mounts can also retain an old inode after atomic host-side replacement. Prefer reviewed immutable configuration artifacts or a directory mount with controlled files, then check what the container actually sees. Our lab uses recreation for configuration or image changes rather than mutating the running config. The command below is an illustration of a reload only if the mounted file is known current.
docker compose -p bm-nginx48 exec edge nginx -tdocker compose -p bm-nginx48 exec edge nginx -s reloadGive graceful shutdown a deadline
Run Nginx in foreground mode so the container tracks its master process. A shell wrapper must forward signals or exec Nginx. SIGQUIT requests graceful shutdown; the worker shutdown timeout bounds draining behavior and the Compose stop grace period should allow additional time before the engine force-kills the process. This does not guarantee every long-lived connection completes. In this fixture, a single edge instance can be briefly unavailable during recreation; production rolling availability requires a separate design.
entrypoint: ["nginx"]command: ["-g", "daemon off;"]stop_signal: SIGQUITstop_grace_period: 20sBudget resources and observe evidence
CPU, memory, process and temporary-storage limits bound a lab but can also create failure modes. More workers do not automatically improve throughput. A memory cap can result in process termination; a small tmpfs can cause buffered-request failures. Use workload measurements, logs and request assertions before changing limits. This illustrative budget is suitable for the tiny static fixture only. Access logs and errors go to container streams; avoid writing real credentials into log fields.
cpus: 0.50mem_limit: 96mpids_limit: 64tmpfs: - /tmp:rw,noexec,nosuid,nodev,size=16m,mode=1777Review an upgrade and keep rollback evidence
Record the previous approved digest and exact configuration in version control. Review the proposed image, platform, modules and configuration diff. With the new approved digest preloaded, validate using the new image, recreate the lab services, check health and both route markers, and review logs. If a check fails, restore both the previous digest and matching configuration and recreate again; do not assume the previous image understands new directives. In this example compose --env-file selects a synthetic file containing only the reviewed image reference. No credentials or real deployment state are included.
docker compose --env-file previous.env -p bm-nginx48 up -d --force-recreate --pull neverdocker compose --env-file previous.env -p bm-nginx48 psUse the Chapter 48 manual practice and lab. Snippets are illustrative; Docker and image execution were not available during authoring. The fixture requires an approved isolated Docker environment and a locally preloaded verified digest.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Graceful container upgrades
Assess decisions from the lesson and original lab.
What does editing a mounted configuration file guarantee?
Which signal requests graceful Nginx shutdown?
What is the risk of replacing one edge instance?
Which artifacts should rollback restore?
What does a passed syntax check establish?