Language-specific details that trip teams up
General Dockerfile rules apply everywhere, but each runtime has its own habits that cause problems in containers. These are the ones we check first when containerizing or reviewing an application.
| Runtime | Common issue | What we do |
| Java (JVM) | Heap sized for the host rather than the container, or a fixed heap that ignores limits | Use a current JDK, which reads container limits, and size the heap with MaxRAMPercentage; consider jlink runtimes or Jib for smaller images |
| Node.js | Started through npm start, so shutdown signals do not reach the app; dev dependencies shipped | Run node directly, install with npm ci and omit dev dependencies in the runtime stage |
| Python | Large images from build tools, slow builds compiling native packages, musl issues on Alpine | Build wheels in a builder stage, use a slim glibc base by default, pin with a lock file |
| Go | Missing CA certificates or time zone data in minimal images | Static binary with CGO_ENABLED=0 on a distroless static base that includes certificates |
| .NET | Full SDK image shipped to production | Separate SDK build stage and runtime stage; Microsoft publishes slim and chiseled runtime images |
| PHP | Web server and PHP-FPM in one container with an ad hoc supervisor | Separate containers or a well-maintained combined image, with OPcache settings tuned for production |
Process behavior: signals, PID 1 and shutdown
Many container bugs only appear during deployments, when Kubernetes stops old pods. The container's main process runs as PID 1, which does not get default signal handling. If the Dockerfile uses the shell form of CMD, a shell becomes PID 1 and may not pass SIGTERM to the application, which is then killed abruptly after the grace period, dropping in-flight requests.
- Use the exec form, for example
CMD ["node", "server.js"], so the application receives signals directly.
- Add a minimal init such as tini when the application spawns child processes, so zombies are reaped.
- Handle SIGTERM in the application: stop accepting new work, finish in-flight requests, close connections, then exit.
- In Kubernetes, a short
preStop delay gives load balancers time to stop sending traffic before shutdown starts, and terminationGracePeriodSeconds should exceed the application's drain time.
- Remember that Kubernetes ignores the Dockerfile
HEALTHCHECK; readiness and liveness probes do that job there.
Building images in CI
Local builds hide problems that CI exposes: cold caches, different architectures, no access to private registries. Our CI image builds use BuildKit through docker buildx with a registry-backed cache, so ephemeral runners still reuse layers. Multi-architecture images for amd64 and arm64 are built either with emulation or, faster, with native runners for each architecture combined into one manifest list.
BuildKit can attach an SBOM and SLSA provenance attestation to each image at build time. Combined with signing, this lets a cluster verify where an image came from before running it. Tags are informative, but deployments reference images by digest so the exact bytes that were tested are the ones that run.
Keeping images patched after they ship
An image that was clean on build day collects vulnerabilities as new advisories appear. Patching needs a routine, not a heroic effort before each audit:
- Pin base images by digest and let Renovate or Dependabot open pull requests when a new digest is published.
- Rebuild on a schedule, even without code changes, so OS package fixes reach production.
- Rescan stored images in the registry against new advisories, and alert on images still running in clusters.
- Patch in place when a rebuild is hard: tools such as Copacetic can apply OS package updates to an existing image, a useful bridge for legacy builds.
- Retire old images with registry lifecycle rules, keeping only versions you still support.
Registry design
The registry is production infrastructure. Decisions we make explicitly: immutable tags for release images, so a tag cannot be overwritten; retention and lifecycle policies so storage does not grow forever; pull-through caches or mirrors for Docker Hub and other public registries, which protect you from upstream rate limits and outages; replication to the regions where clusters run; and scanning plus signature storage alongside the images. For air-gapped or on-premises sites, Harbor provides replication, scanning and access control in one self-hosted product. Access follows least privilege as well: CI identities can push only to their own repositories, clusters can only pull, and nobody pushes release images by hand from a laptop. Registry audit logs record who pushed what and when, which is often the first place to look when an unexpected image appears in a cluster.
Development environments that match production
Containers help most when development, CI and production share the same definitions. Docker Compose describes the local stack; Compose Watch syncs code changes into running containers without full rebuilds. The Dev Container specification, supported by VS Code and other editors, defines a complete development environment in the repository, so a new engineer opens the project and gets the right toolchain without a setup document. The production image remains the source of truth: development images extend it rather than duplicating it.
Once images are solid, the next steps are usually Kubernetes or a simpler managed container service, with supply-chain controls for signing and admission. Our migration kits package common containerization patterns.