Docker Architecture & Concepts
Understand the engine under the hood. You cannot secure what you do not understand.
Containers vs. Virtual Machines
VMs virtualize hardware via a Hypervisor. Containers virtualize the Operating System. Containers share the host OS kernel. This makes them fast, lightweight, and portable.
Virtual Machine
Bins/Libs
Guest OS
Bins/Libs
Guest OS
Docker Container
Bins/Libs
Bins/Libs
DevSecOps: Hardening Docker
Out-of-the-box Docker is insecure. Apply these baseline rules.
1. Never Run as Root
Processes run as root by default. Create a restricted user in your Dockerfile.
USER appuser
2. Image Scanning
Integrate Trivy or Snyk into your CI/CD pipeline. Block builds with Critical CVEs.
3. Drop Capabilities
Drop all Linux capabilities. Add back only what the process requires.
4. Read-Only Filesystem
Prevent attackers from installing malware inside the running container.
The Docker Sock Vulnerability
Do not bind mount /var/run/docker.sock into a container. Anyone with access to that socket executes commands as root on the host machine.
Compose Anatomy
Docker Compose orchestrates multi-container applications.
version: '3.8'
services:
api:
build: ./api
environment:
- DB_HOST=db
- DB_USER=${DB_USER} # Use .env files for secrets
networks:
- backend
depends_on:
- db
db:
image: postgres:14
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
volumes:
db-data:
networks:
backend:
CLI Command Dictionary
Search the complete Docker command syntax library.