Updated on November 4, 2026
Docker container security comes down to 15 controls applied across the container lifecycle: harden and scan images at build time, verify what enters the registry and the cluster, restrict what containers can do at runtime, and watch running workloads for behaviour that drifts from the image. Containers are built from layered images, pulled from registries and run on a shared kernel. One weak link, such as an outdated base image, a leaked secret or an exposed daemon socket, can reach production quickly. This guide, updated for November 2026, covers each control with the Dockerfile lines, docker run flags and Kubernetes settings that implement it. It also explains how responsibilities shift between standalone Docker, Kubernetes and Amazon ECS, and which five controls to start with when time is short.
Key takeaways
- ✓Containers share the host kernel, so a container is a process boundary rather than a virtual machine boundary, and runtime restrictions matter as much as image scanning.
- ✓Minimal base images, pinned digests, multi-stage builds and a non-root USER remove most image-level risk before anything is deployed.
- ✓Image signing, SBOMs and admission policies stop untrusted or unscanned images from reaching production.
- ✓Dropping all Linux capabilities, using a read-only root filesystem and applying seccomp or AppArmor profiles limit what an attacker can do after a compromise.
- ✓Runtime monitoring for shell spawns, unexpected file writes, new network connections and image drift catches attacks that static scans cannot see.
What is Docker container security?
Docker container security is the set of controls that protect containerised applications at every stage, from the Dockerfile to the running process and the host underneath it. Ask what container security is in general and you get the same scope: images, registries, orchestrators, containers and host operating systems. NIST container security guidance in SP 800-190, Application Container Security Guide, groups risks into exactly those five areas.
Core Docker terms
- Image: a read-only, layered package of an application and its dependencies, built from a Dockerfile. Every layer persists in the image history.
- Container: a running instance of an image, isolated with Linux namespaces and limited with cgroups, but still a process on the host kernel.
- Docker daemon (dockerd): the service that builds, pulls and runs containers. It normally runs as root and listens on
/var/run/docker.sock. - Client: the
dockerCLI, which sends API requests to the daemon locally or over the network. - Registry: the store for images, such as Docker Hub, Amazon ECR, Google Artifact Registry or a private Harbor instance.
The container lifecycle
Each stage is a control point, and the 15 practices below map onto it:
- Build: write the Dockerfile, choose a base image, compile the application.
- Scan and inventory: check OS packages and dependencies for CVEs, then generate an SBOM.
- Sign: attach a cryptographic signature and build provenance.
- Store: push to a registry with access control and TLS.
- Admit and deploy: CI/CD and admission policies decide whether the image may run.
- Run: the container executes with restricted privileges and network access.
- Monitor and respond: detect anomalous behaviour, collect evidence, rebuild from a clean image.
Why is Docker container security challenging?
Containers share the host kernel, and they depend on many moving parts that each need their own controls. A virtual machine runs its own kernel on a hypervisor, so escaping it means breaking the hypervisor. A container is a set of namespaced processes on the host kernel, so a kernel exploit, a privileged flag or a host mount can turn a container compromise into a host compromise.
What containers isolate
- ✓Process trees, filesystems, network stacks and hostnames between workloads.
- ✓CPU, memory and process counts through cgroups, when you set limits.
What containers do not isolate
- ✗The kernel: every container on a node runs on the same one.
- ✗Root: UID 0 inside a container is UID 0 on the host unless user namespaces or rootless mode remap it.
Docker-specific risks and the controls that address them
| Risk | How it happens | Practices |
|---|---|---|
| Container breakout | Kernel exploit, --privileged, host path mounts, root processes |
4, 11, 12 |
| Daemon socket exposure | Mounting docker.sock or exposing TCP 2375 without TLS |
9 |
| Vulnerable base images | Outdated packages in latest or full OS images |
1, 2, 6 |
| Secret leakage in layers | ENV or COPY .env persists in image history |
5 |
| Supply-chain poisoning | Typosquatted images, compromised dependencies, tampered builds | 7, 8, 10 |
| Over-permissive capabilities | Defaults such as NET_RAW, or adding SYS_ADMIN |
11 |
| Insecure registries | Plain HTTP registries, broad push permissions | 9 |
| Lateral movement | Flat networks and unrestricted egress | 13 |
Shared responsibility by platform
Who owns each control depends on where containers run, which is why Kubernetes container security and AWS container security on ECS look different from standalone Docker:
| Platform | You secure | Key extra controls |
|---|---|---|
| Standalone Docker on a VM | Host OS, kernel, daemon, networks, every container setting | Daemon TLS, rootless mode, CIS Docker Benchmark |
| Kubernetes (EKS, GKE, AKS, self-managed) | Nodes, workloads, RBAC, admission, NetworkPolicy; managed services run the control plane | Pod Security Admission, admission policies, service account scoping |
| Amazon ECS on EC2 | Container instances, task definitions, task IAM roles | Least-privilege task roles, awsvpc security groups |
| Amazon ECS on Fargate | Images, task definitions, IAM roles; AWS manages the host | No host access or privileged containers, so focus on image and IAM controls |
Build-time best practices: harden the image
The most effective Docker security best practices start in the Dockerfile, because every package, file and permission you leave out of the image is one an attacker cannot use.
1. Start from minimal, trusted base images
A full ubuntu or node image ships shells, package managers and hundreds of libraries your application never calls, and each one can carry CVEs. Use distroless images (no shell or package manager), -slim variants, or Alpine where musl libc compatibility is not a problem. Pull only Docker Official Images, verified publishers or internally built images, and rebuild on a schedule so base layer patches actually land.
2. Pin tags and digests instead of latest
latest is a moving pointer, so the image you scanned on Monday may not be the one you deploy on Friday. Pin a version tag plus a SHA-256 digest, for example FROM node:20-bookworm-slim@sha256:<digest>, so builds are reproducible and a tampered upstream tag cannot slip in. Renovate or Dependabot can raise pull requests when new digests are published.
3. Use multi-stage builds
Multi-stage builds compile in one stage and copy only runtime artefacts into a clean final stage, leaving compilers, build tools and source code behind. Unlike a single-stage FROM node:latest build with an ENV API_KEY line, this hardened version pins digests, mounts the npm token as a secret and ends on distroless:
# syntax=docker/dockerfile:1
FROM node:20-bookworm-slim@sha256:<digest> AS build
WORKDIR /app
COPY package*.json ./
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci --omit=dev
COPY . .
FROM gcr.io/distroless/nodejs20-debian12@sha256:<digest>
WORKDIR /app
COPY --from=build /app /app
USER nonroot
CMD ["server.js"]4. Run as a non-root user
Containers run as root by default, which turns any breakout bug into host root unless user namespaces remap it. Create a dedicated user with a fixed high UID (RUN useradd -u 10001 app) and set USER 10001, or use the built-in nonroot user in distroless images. On standalone hosts, enable Docker rootless mode or userns-remap in daemon.json so container root maps to an unprivileged host UID.
5. Keep secrets out of image layers
Anything written by ENV, ARG or COPY stays in the layer history, and docker history or a layer extraction reveals it even if a later step deletes the file. Use BuildKit secret mounts (--mount=type=secret) for build-time credentials and add .env, .git and key files to .dockerignore. Inject runtime secrets from AWS Secrets Manager, HashiCorp Vault or Kubernetes Secrets mounted as files. Avoid environment variables, which leak through docker inspect and crash dumps.
Supply chain, registry and deployment best practices
Supply-chain controls prove that the image running in production is the one you built, scanned and approved, and nothing else.
6. Run Docker container vulnerability scanning continuously
Docker image security scanning has to cover OS packages (apt, apk, rpm) and application dependencies (npm, pip, Maven, Go modules). Scan in CI and fail the build on fixable critical findings, for example trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 registry.example.com/api:1.4.2, or use Grype or Docker Scout. New CVEs are published daily, so rescan images already in the registry and in production. Container image scanning finds the issues; a container vulnerability management process decides which to fix first, ideally based on whether the vulnerable package is actually loaded at runtime.
7. Generate and validate SBOMs
A software bill of materials lists every component in an image, so when a new CVE drops you can answer “where do we run this library?” in minutes. Generate SBOMs at build time with docker buildx build --sbom=true --provenance=true or syft <image> -o cyclonedx-json, in SPDX or CycloneDX format. Store them alongside the image as attestations and validate in CI that every image ships with one.
8. Sign images and verify provenance
Signing proves who built an image and that it has not changed since. Sign by digest with Sigstore Cosign (cosign sign --key cosign.key registry.example.com/api@sha256:<digest>, or keyless signing through your CI identity) or with Notary v2 / Notation. Attach SLSA build provenance describing the source commit and builder, and run cosign verify before deployment.
9. Lock down registries and the Docker daemon
Serve registries only over TLS, remove insecure-registries entries from daemon.json, restrict push rights to CI service accounts and enable tag immutability where supported (Amazon ECR and Harbor support it). Never expose the daemon on unauthenticated TCP port 2375. For remote access, use port 2376 with --tlsverify and client certificates, or SSH.
Mounting /var/run/docker.sock into a container gives it full control of the daemon, which means root on the host. Treat any socket mount, including in CI runners and monitoring agents, as a privileged-access decision.
10. Enforce policy in CI/CD and admission control
Policy as code turns these rules into gates. In CI, block images that fail scanning, lack an SBOM or are unsigned. In Kubernetes, enable Pod Security Admission at the restricted level and use Kyverno or OPA Gatekeeper to reject pods with unsigned images, mutable tags, hostPath mounts or privileged settings. Admission decisions are logged, so auditors get evidence of enforcement instead of a policy document.
Docker runtime security best practices
Docker runtime security limits what a running container can do and detects when it does something it should not, which is where image scanning stops helping.
11. Drop capabilities and make the filesystem read-only
Docker grants default Linux capabilities, including NET_RAW and CHOWN, that most applications never need. Drop them all, add back only what is required, block setuid privilege escalation and set resource limits:
docker run -d --name api \
--user 10001:10001 \
--read-only --tmpfs /tmp:rw,noexec,nosuid,size=64m \
--cap-drop ALL --cap-add NET_BIND_SERVICE \
--security-opt no-new-privileges:true \
--memory 512m --pids-limit 200 \
registry.example.com/api@sha256:<digest>Docker Compose deployments apply the same controls through the user, read_only, cap_drop, cap_add, security_opt, mem_limit and pids_limit keys in each service definition.
12. Apply seccomp, AppArmor or SELinux and avoid privileged mode
Seccomp filters which system calls a container can make, and Docker’s default profile already blocks several dozen risky ones, so never run with seccomp=unconfined. Add AppArmor (Ubuntu, Debian) or SELinux (RHEL, Fedora) profiles for mandatory access control. Never use --privileged, --pid=host, --network=host or --ipc=host for application workloads. The Kubernetes equivalent:
spec:
hostNetwork: false
hostPID: false
hostIPC: false
containers:
- name: api
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault13. Segment networks and restrict egress
The default Docker bridge lets every container talk to every other container. On standalone hosts:
- Create user-defined networks per application tier, with
docker network create --internal backendfor tiers that need no internet access. - Bind published ports to specific interfaces (
-p 127.0.0.1:8080:8080). - Set
"icc": falseindaemon.json.
In Kubernetes, apply a default-deny NetworkPolicy, then allow only required service-to-service flows. Restrict egress to known destinations so a compromised container cannot download tooling or exfiltrate data, and encrypt internal traffic with mutual TLS through a service mesh such as Istio or Linkerd.
14. Monitor runtime behaviour and image drift
Runtime container security relies on watching what processes actually do. Container behaviour is predictable. A web API should not spawn /bin/sh, run apk add or write to /usr/bin. Alert on these signals:
- Shells or interactive terminals spawned inside application containers
- Executables that did not exist in the original image (drift)
- Writes to binary directories or reads of
/etc/shadowand service account tokens - Outbound connections to new destinations, mining pools or the cloud metadata endpoint
eBPF-based tools such as Falco and Tetragon collect these events at the kernel level with low overhead. Cloud runtime security works best when each alert says which image, registry, build and identity the container used.
15. Prepare a container incident response playbook
Containers are short-lived, so evidence disappears when a pod is rescheduled. Write the playbook before you need it:
- Isolate the container with a quarantine NetworkPolicy or
docker network disconnectinstead of killing it. - Freeze processes with
docker pauseand capturedocker inspect,docker diffanddocker exportoutput. - Pull container logs, Kubernetes audit logs and cloud audit logs into your SIEM.
- Rotate every secret and credential the container could reach.
- Redeploy from a known-good, signed image rather than patching in place, then fix the root cause in the Dockerfile or pipeline.
Centralised logs, signed provenance and admission records also form the audit trail for SOC 2 and PCI DSS.
How Upwind adds runtime context to Docker container security
Upwind connects the build, registry and runtime practices above through a lightweight eBPF sensor that shows what is actually executing inside containers, instead of inferring risk from snapshots. That makes it a practical way to apply cloud container security best practices across AWS, Google Cloud and Kubernetes. Its AI agents use the runtime data to investigate threats and generate fixes. Upwind holds a 4.8/5 rating from 88 reviews on Gartner Peer Insights as of November 2026, with reviewers highlighting runtime visibility and alerting accuracy in AWS, GCP and container environments. The sensor cannot run on AWS Fargate for Amazon ECS, AWS Lambda or Google Cloud Run, so fully serverless container estates get less runtime depth.
- ✓Shows which vulnerable packages are loaded and which workloads are reachable
- ✓Flags shell spawns and other live process behaviour as it happens
- ✓Ties a running container back to its registry and build source
Where to start: priorities and final checklist
Teams with limited time should start with the controls that block the most common and most damaging attack paths, then add depth stage by stage.
If you only do five things
- Run every container as non-root with all capabilities dropped and
no-new-privilegesset. - Scan images in CI and fail builds on fixable critical CVEs.
- Never mount
docker.sock, run--privilegedor expose the daemon without TLS. - Move secrets out of images and environment variables into a secrets manager.
- Monitor runtime for shell spawns, drift and unexpected outbound connections.
Then add depth by effort
- Low effort: pin digests, add
.dockerignore, use--read-only, keep the default seccomp profile. - Medium effort: multi-stage builds on minimal bases, user-defined networks with egress rules, Pod Security Admission at
restricted. - Higher effort: Cosign signing with SLSA provenance, SBOM attestations, Kyverno or Gatekeeper policies, mTLS and a tested incident playbook.
For an independent reference, OWASP container security guidance in the Docker Security Cheat Sheet and the CIS Docker Benchmark both align with these controls. No single scanner or flag delivers strong Docker container security. It takes build-time hardening, a verified supply chain, a restricted runtime and fast detection together, and each link covers gaps the others leave.
FAQ
What is Docker container security?
Docker container security is the set of controls that protect containerized applications across the full lifecycle, from the Dockerfile and image to the registry, orchestrator, running container, and host operating system.
Why is Docker container security challenging?
Docker security is challenging because containers share the host kernel. That means a kernel exploit, privileged flag, root process, or unsafe host mount can turn a container compromise into a host compromise more easily than in a virtual machine model.
Which build-time practices reduce Docker image risk the most?
The article highlights minimal trusted base images, pinned tags and digests, multi-stage builds, running as a non-root user, and keeping secrets out of image layers as the most effective build-time controls.
Why does runtime security still matter if images are scanned?
Image scanning finds known vulnerabilities before deployment, but it cannot see what a container actually does when running. Runtime security adds controls such as dropped capabilities, read-only filesystems, seccomp, network restrictions, and monitoring for shell spawns, drift, unexpected writes, and suspicious outbound connections.
If time is short, which five Docker container security controls should teams start with?
Start by running containers as non-root with all capabilities dropped and no-new-privileges enabled, scanning images in CI and failing builds on fixable critical CVEs, never mounting docker.sock or using privileged mode, moving secrets into a secrets manager, and monitoring runtime for shell spawns, image drift, and unexpected outbound traffic.
