Docker and Container Security MOC
Hub for concepts, runbooks, labs and post-mortems on Docker, Docker Compose and container security.
┌────────────────────────────────────┐
│ Docker and Container Security MOC │
└─────────────────┬──────────────────┘
│
┌────────────────────────┬────────┴───────────────┬────────────────────────┐
▼ ▼ ▼ ▼
┌──────────────┐ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ Networking │ │ Supply Chain │ │ Runbooks & │ │ Labs, Posts & │
│ & Exposure │ │ & Reproducib. │ │ How-Tos │ │ Case Studies │
└──────────────┘ └────────────────┘ └────────────────┘ └────────────────┘
Core concepts
Fundamentals
- A Container Shares the Host Kernel, a Virtual Machine Runs Its Own: namespaces, cgroups and OverlayFS; why root in a container matters.
- Rebuilding an Image Does Not Update the Container Already Running It:
buildvsrestartvsup -d --no-deps, checking the running image. - Containers Without a Restart Policy Stay Down After a Host Reboot:
no,on-failure,always,unless-stopped; proxy 503s and SNI errors from stopped backends. - Files Written to an Unmounted Container Path Live Only in That Container's Layer: default write paths without volumes, and matching paths between cooperating containers.
Networking & exposure control
- Docker Port Binding and Host Firewall Bypass: why
"HOST:CONTAINER"mappings listen on every interface and bypassufw, loopback binding,DOCKER-USER, and the CVE-2025-54388 caveat. - One Shared Reverse Proxy Can Route Many Compose Projects by Host Name: nginx-proxy on a shared network,
VIRTUAL_HOST, acme-companion andNGINX_PROXY_CONTAINER. - An App Behind a TLS-Terminating Proxy Builds http URLs Unless It Trusts Forwarded Headers:
X-Forwarded-Proto, Uvicorn--proxy-headers, trusting only the proxy's IP.
Supply chain & reproducibility
- Container Image Version Pinning vs Mutable Tags:
:latestvs release tags vs digests, third-party images, and the update process pinning requires.
Build, runtime & filesystem hardening
- Container Entrypoint Hardening and Gunicorn Worker Configuration: fail-fast
set -eentrypoints, Composeservice_healthyover brokenncwait loops, avoiding runtimecollectstatic --clear, and multi-worker Gunicorn tuning (--workers 3 --timeout 60 --access-logfile -). - Multi-Stage Docker Builds for Frontend Assets and Static Collection: compiling Tailwind CSS (
npm ci+--minify) in a builder stage prior tocollectstatic, strippingnode_modulesfrom the runtime image, and scanning dynamic JS files (./static/js/main.js). - Docker Build Context Isolation and Bind-Mount Masking: excluding
.venv/,node_modules/,staticfiles/, andmediafiles/in.dockerignore, and masking/app/node_moduleswith an anonymous volume over a host bind mount. - uv in a Multi-Stage Build Must Use the Image's Python or the Copied venv Breaks:
UV_PYTHON_PREFERENCE=only-system, minor-version pins, the misleadingexec ... no such file or directory. - Browsers Refuse a Stylesheet Served with the Wrong Content-Type: strict MIME checking,
mimetypes.add_type()at startup, checking withcurl -I. - File Watchers in a Container Miss Host Edits Unless They Poll: inotify across VM mounts (Colima, Docker Desktop), polling options, watchers outside the app process.
- Non-Root Container Filesystem Ownership and Persistent Media Volumes:
ENV APP_HOMEandmkdirordering beforechown -R appuser:appuser, aligningSTATIC_ROOTandMEDIA_ROOT, persistentmedia_datavolumes, and port-mappedCSRF_TRUSTED_ORIGINS.
Runbooks (05 - SOPs & Manuals/)
- Install Docker Engine and the Compose Plugin on Debian or Ubuntu: Docker's apt repository,
docker-compose-plugininstead of v1, the root-equivalentdockergroup. - Docker Compose Cheat Sheet: everyday
docker composecommands, prune, and a full clean rebuild without losing data by accident. - Access Loopback-Bound Docker Admin Services via SSH Tunneling: pin the running image, bind
pgAdmin4to127.0.0.1, reach it withssh -N -L. - Setup django-debug-toolbar in a dockerized app: Docker bridge IP ranges in
INTERNAL_IPSfor local debugging. - Host Multiple Docker Compose Projects behind a Shared nginx-proxy: shared
webproxynetwork, nginx-proxy and acme-companion, ACME, DNS, restart and proxy-header troubleshooting.
Labs (02 - Sources/)
- Docker Compose Production Hardening – pgAdmin Service Review: review of
pgadmin4indocker-compose-prod.yml: loopback binding and image pinning. - Docker and Django Build and Runtime Hardening – Entrypoint, Multi-Stage Assets, and Compose Volumes: hardening
entrypoint.sh, multi-stage Tailwind CSS +collectstaticbuilds,.dockerignoreisolation, non-root directory ownership, and Compose volumes.
Post-mortems & case studies (06 - Posts/)
- Specify the versions of the softwares you install on your server: unpinned
docker-composeand image versions breaking a production deployment. - Debugging Django email in Docker: a case study: environment variables and SMTP connectivity inside Compose stacks.
Related maps
- Kubernetes MOC: running containers across a cluster.
- Web Application and Django Security MOC: application-layer security, bot filtering, per-IP rate limiting, and SMTP resilience for containerized Django apps.
Open questions
- Should admin tools sit behind a VPN (WireGuard, Tailscale) rather than per-service SSH tunnels?
- Which update bot (Renovate or Dependabot) fits the Compose repos, and how are bumps tested against volumes?
- Switch from
elestio/pgadminto the upstreamdpage/pgadmin4image?
References
- Docker Engine Security Documentation - Namespaces, control groups, daemon attack surface and other container security primitives.
- Docker Docs: Packet filtering and firewalls - Docker's
iptablesintegration and how it interacts with host firewalls.