Add docker-images: one Spring Boot 4 service packaged nine ways
Companion code for "Dockerizing Spring Boot 4: Layered Jars, Buildpacks, Distroless and Image Size Benchmarks". Fat jar on JDK and JRE, layered jar on Debian, Alpine and distroless, jlink, the JDK 25 AOT cache, Paketo buildpacks and Jib, each measured for size on disk and pushed, rebuild delta, startup, user and shell. Also PID 1 and signal handling, the jdeps module gap, AOT cache mismatches and buildpacks memory calculation. Transcripts in docs/output/, regenerated by scripts/run-all.sh. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C3TETMrqVUWeFkNtz3Jbo3
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# 7. PID 1 and signals
|
||||
|
||||
[← 6. AOT cache](06-aot-cache.md) · [Index](../README.md) · Next: [8. Living with distroless →](08-distroless-in-practice.md)
|
||||
|
||||
`docker stop` - and Kubernetes, on pod deletion - sends SIGTERM to PID 1, waits (10 s for Docker,
|
||||
`terminationGracePeriodSeconds` for Kubernetes), then SIGKILLs. Spring Boot's graceful shutdown only
|
||||
runs if the JVM receives that SIGTERM.
|
||||
|
||||
[`pid1-and-signals.txt`](output/pid1-and-signals.txt):
|
||||
|
||||
```
|
||||
layered-jre PID 1: java -jar application.jar docker stop: 244 ms exit code: 143 graceful-shutdown log lines: 1
|
||||
shell-form PID 1: /bin/sh -c java -jar /app/app.jar docker stop: 10160 ms exit code: 137 graceful-shutdown log lines: 0
|
||||
shell-form-alpine PID 1: java -jar /app/app.jar docker stop: 219 ms exit code: 143 graceful-shutdown log lines: 1
|
||||
shell-form-wrapper PID 1: /bin/sh -c echo "starting revision $(date +%s)" && java -j docker stop: 10176 ms exit code: 137 graceful-shutdown log lines: 0
|
||||
```
|
||||
|
||||
- **Exec form** (`["java", "-jar", ...]`): the JVM is PID 1, SIGTERM arrives, graceful shutdown
|
||||
runs, exit code 143, a quarter of a second.
|
||||
- **Shell form on `eclipse-temurin:25-jre`**: `/bin/sh` is dash (`/usr/bin/dash`). dash stays
|
||||
resident as PID 1 and does not forward SIGTERM. Docker waits the full 10 s and SIGKILLs: exit 137,
|
||||
no graceful shutdown, in-flight requests cut off.
|
||||
- **The same shell form on the Alpine image works**, because `/bin/sh` there is BusyBox ash, which
|
||||
replaces itself with the last command of a `-c` string. The same Dockerfile line behaves
|
||||
differently depending on the base image - which is how "it works on my image" arguments start.
|
||||
- **Any shell form with more than one command** keeps the shell as PID 1 regardless.
|
||||
|
||||
If you need a wrapper script, end it with `exec java ...`. Distroless removes the question: with no
|
||||
`/bin/sh`, a shell-form `ENTRYPOINT` cannot even start.
|
||||
Reference in New Issue
Block a user