Running containers in production without security hardening is one of the most common mistakes teams make. A default Docker installation ships with dozens of configuration choices that deviate from security best practices — running as root, sharing the host namespace, exposing privileged ports, and mounting sensitive filesystem paths without restriction.
This guide compares three open-source tools that audit and enforce container security baselines: Docker Bench for Security, Trivy, and Checkov. Each takes a different approach to hardening, from CIS benchmark compliance checks to infrastructure-as-code misconfiguration scanning. We’ll cover installation, configuration, and real-world usage so you can pick the right tool for your self-hosted environment.
Why Harden Your Containers?
Containers share the host kernel, which means a misconfigured container can compromise the entire system. The CIS Docker Benchmark alone lists over 100 security checks covering host configuration, Docker daemon settings, container runtime options, and image build practices.
Hardening your containers addresses three core risks:
- Privilege escalation — containers running as root or with
--privilegedflag can escape to the host - Data exposure — volumes mounted without
:ro(read-only) flags allow write access to sensitive host paths - Network exposure — containers binding to
0.0.0.0without firewall rules are reachable from any network
The tools covered in this guide automate the detection of these misconfigurations, saving hours of manual audit work.
Docker Bench for Security: CIS Benchmark Auditing
Docker Bench for Security is the official Docker Inc. tool that implements the CIS Docker Benchmark as an automated shell script. It runs dozens of checks against your Docker host configuration, daemon settings, and running containers.
| Attribute | Docker Bench for Security |
|---|---|
| GitHub | docker/docker-bench-security |
| Stars | 9,623 |
| Language | Shell |
| Last Updated | October 2024 |
| License | Apache 2.0 |
| Focus | CIS Docker Benchmark compliance |
| Deployment | Docker container or host script |
How It Works
The tool connects to your Docker daemon (read-only via the socket) and runs a series of checks organized into categories:
- Host configuration — kernel parameters, AppArmor/SELinux status, partitioning
- Docker daemon configuration — storage driver, logging, live restore, user namespaces
- Daemon configuration files — permissions on
/etc/docker/daemon.json - Container images and build files —
docker commit,HEALTHCHECKpresence, update policies - Container runtime — privileged mode, PID namespace sharing, network mode, memory limits
- Docker security operations — swarm mode, secrets management
- Docker swarm configuration — manager/workernode settings (if applicable)
Each check is marked as PASS, WARN, or INFO, making it easy to spot failures at a glance.
Installation via Docker Compose
The easiest way to run Docker Bench is inside a container with access to the host Docker socket and relevant filesystem paths:
| |
Build and run:
| |
Running Specific Tests
You can target specific test categories using the -t flag:
| |
Sample Output
| |
Trivy: Multi-Purpose Security Scanner
Trivy by Aqua Security is a comprehensive security scanner that goes far beyond container hardening. It scans container images, filesystems, Git repositories, and Kubernetes clusters for vulnerabilities, misconfigurations, secrets, and software bill of materials (SBOM).
| Attribute | Trivy |
|---|---|
| GitHub | aquasecurity/trivy |
| Stars | 34,718 |
| Language | Go |
| Last Updated | April 2026 |
| License | Apache 2.0 |
| Focus | Vulnerabilities, misconfigurations, secrets, SBOM |
| Deployment | CLI binary or Docker container |
Container Misconfiguration Scanning
Trivy’s config scanner supports Docker Compose, Dockerfile, and Kubernetes manifests. It checks against built-in policies derived from CIS benchmarks and best practices:
| |
Sample Misconfiguration Output
| |
Installing Trivy
| |
Running as a Self-Hosted Scanner
You can run Trivy on a schedule via cron to audit all running images:
| |
Add to crontab for daily runs:
| |
Checkov: Infrastructure-as-Code Security
Checkov by Bridgecrew (now part of Prisma Cloud) is a static analysis tool for infrastructure-as-code. It scans Terraform, CloudFormation, Kubernetes, Dockerfile, and Docker Compose files against hundreds of built-in policies covering security, compliance, and best practices.
| Attribute | Checkov |
|---|---|
| GitHub | bridgecrewio/checkov |
| Stars | 8,670 |
| Language | Python |
| Last Updated | April 2026 |
| License | Apache 2.0 |
| Focus | IaC misconfiguration scanning across cloud providers |
| Deployment | Python package or Docker container |
Docker and Compose Scanning
Checkov includes policies specifically for Dockerfile and Docker Compose files:
| |
Sample Output
| |
Installing Checkov
| |
Comparison: Docker Bench vs Trivy vs Checkov
| Feature | Docker Bench | Trivy | Checkov |
|---|---|---|---|
| Primary Focus | CIS Docker Benchmark | Multi-purpose security | IaC misconfiguration |
| Dockerfile Scanning | Partial (build checks) | Yes | Yes (detailed policies) |
| Docker Compose | No (runtime only) | Yes | Yes |
| Running Container Audit | Yes (primary feature) | No | No |
| Vulnerability Scanning | No | Yes (CVE database) | No |
| Secret Detection | No | Yes | No |
| Kubernetes Scanning | No | Yes | Yes |
| Custom Policies | No | Yes (Rego/OPA) | Yes (Python/YAML) |
| CI/CD Integration | Manual/scripted | Native | Native (GitHub Actions) |
| Output Formats | Console only | JSON, SARIF, Table, CycloneDX | JSON, JUnit, SARIF, CLI |
| Language | Shell | Go | Python |
| Stars | 9,623 | 34,718 | 8,670 |
| Best For | Runtime compliance checks | Comprehensive scanning | Build-time IaC checks |
When to Use Each Tool
- Docker Bench — Run periodically on production hosts to verify CIS Docker Benchmark compliance. Best for audit and compliance teams who need documented proof of security posture.
- Trivy — Use as your all-in-one scanner in CI/CD pipelines. Catches vulnerabilities, misconfigurations, and secrets in a single pass. Ideal for development teams.
- Checkov — Deploy as a pre-commit or CI gate for infrastructure-as-code files. Its granular policy controls make it the best choice for enforcing standards across Docker Compose and Dockerfile repositories.
Recommended Hardening Workflow
For a complete self-hosted container security pipeline, combine all three tools at different stages:
Stage 1: Build-Time Checks (Checkov + Trivy)
| |
Stage 2: Image Scanning (Trivy)
After building your container image, scan for vulnerabilities:
| |
Stage 3: Runtime Auditing (Docker Bench)
Schedule Docker Bench to run weekly on production hosts:
| |
| |
Hardening Quick-Reference Checklist
| |
Hardened Docker Compose Example
Here’s a production-ready compose file that passes most Docker Bench checks:
| |
Key hardening principles applied:
- Non-root user — every container runs as UID 1000
- Read-only filesystem — mutable state isolated to tmpfs and named volumes
- Capability dropping — all capabilities dropped, only
NET_BIND_SERVICEre-added where needed - No new privileges — prevents privilege escalation via setuid binaries
- Resource limits — memory and CPU caps prevent runaway containers
- Internal network — backend network not exposed to host
- Healthchecks — enables automatic restart on failure
- Pinned image tags — no
latesttags for reproducible builds
Additional Hardening Tips
Enable User Namespace Remapping
User namespace remapping maps container root to an unprivileged host user:
| |
Enable AppArmor or SELinux Profiles
| |
Disable Inter-Container Communication
| |
Use Content Trust for Image Verification
| |
For related reading on container security, see our container image scanning guide and Kubernetes hardening comparison. If you’re also managing IaC security, check our Checkov vs TFsec vs Trivy comparison.
FAQ
What is the CIS Docker Benchmark?
The CIS Docker Benchmark is a set of security configuration guidelines published by the Center for Internet Security. It covers host configuration, Docker daemon settings, container images, and runtime options. Docker Bench for Security automates these checks, making compliance verification a single command.
Can Trivy replace Docker Bench for Security?
Not entirely. Trivy excels at scanning container images and IaC files for misconfigurations and vulnerabilities, but it does not audit running containers or the Docker daemon configuration on the host. Docker Bench fills this gap by checking the live environment. For comprehensive coverage, use both: Trivy at build time and Docker Bench at runtime.
Does Checkov scan running containers?
No. Checkov performs static analysis on infrastructure-as-code files (Dockerfile, docker-compose.yml, Terraform, etc.). It catches misconfigurations before deployment but cannot audit containers already running on a host. Pair it with Docker Bench for full lifecycle coverage.
How often should I run container security audits?
Run Trivy scans on every build in your CI/CD pipeline (zero extra cost). Run Checkov as a pre-commit hook or PR check. Run Docker Bench on production hosts weekly via cron, and immediately after any Docker daemon configuration change or host update.
What is the difference between vulnerability scanning and misconfiguration scanning?
Vulnerability scanning checks for known CVEs in package dependencies (e.g., OpenSSL 1.1.1 has CVE-2023-0464). Misconfiguration scanning checks for insecure settings (e.g., container running as root, privileged mode enabled). Trivy does both; Docker Bench and Checkov focus on misconfigurations only.
Can I write custom policies for these tools?
Trivy supports custom policies via Rego (OPA) language for config scanning. Checkov allows custom policies in Python or YAML format. Docker Bench does not support custom policies — it strictly implements the CIS Docker Benchmark. If you need custom runtime checks, consider combining Docker Bench output with a custom script.
Are these tools suitable for production environments?
Yes. All three tools are read-only by design. Docker Bench connects to the Docker socket in read-only mode. Trivy and Checkov analyze files without modifying them. None of these tools change your system configuration — they only report findings.