Skip to content

Docker Bench for Security

50 commands

A script that checks a Docker host against dozens of CIS Docker Benchmark best practices for production deployments.

  • Docker
  • CIS benchmark
  • hardening

Install Docker Bench for Security

git clone https://github.com/docker/docker-bench-security.git && cd docker-bench-security && sudo sh docker-bench-security.sh

Basic Execution3

sudo ./docker-bench-security.sh

Executes the full CIS Docker Benchmark audit script against the local host using default settings.

docker run --rm --net host --pid host --userns host --cap-add audit_control -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --label docker_bench_security docker/docker-bench-security

Runs Docker Bench for Security from a container with necessary volume mounts and privileges to audit the host.

sudo ./docker-bench-security.sh -h

Displays the help menu listing all available flags and execution options.

Output and Reporting4

sudo ./docker-bench-security.sh -l <filename>

Runs the benchmark and saves the output to a specified log file in the current directory.

Link
sudo ./docker-bench-security.sh -p

Prevents the script from writing any log files to disk, outputting only to stdout.

sudo ./docker-bench-security.sh -j

Outputs the audit results in JSON format to the console for parsing.

Link
sudo ./docker-bench-security.sh -j -l output.json

Runs the benchmark and saves the results in JSON format to a specific file.

Link

Host and Daemon Configuration3

sudo ./docker-bench-security.sh -c host_configuration

Limits the audit strictly to Section 1: Host Configuration checks.

sudo ./docker-bench-security.sh -c docker_daemon_configuration

Limits the audit strictly to Section 2: Docker Daemon Configuration checks.

sudo ./docker-bench-security.sh -c docker_daemon_configuration_files

Limits the audit strictly to Section 3: Docker Daemon Configuration Files checks.

Image and Build Configuration1

sudo ./docker-bench-security.sh -c container_images

Limits the audit strictly to Section 4: Container Images and Build File checks.

Container and Runtime Security3

sudo ./docker-bench-security.sh -c container_runtime

Limits the audit strictly to Section 5: Container Runtime checks.

Link
sudo ./docker-bench-security.sh -c docker_security_operations

Limits the audit strictly to Section 6: Docker Security Operations checks.

Link
sudo ./docker-bench-security.sh -c docker_swarm_configuration

Limits the audit strictly to Section 7: Docker Swarm Configuration checks.

Link

Specific Check Targeting2

sudo ./docker-bench-security.sh -c check_1.1

Runs only the specific check 1.1 regarding Linux Kernel Capabilities.

Link
sudo ./docker-bench-security.sh -c check_2.1,check_2.2

Runs a comma-separated list of specific checks, ignoring all others.

Link

Excluding Checks3

sudo ./docker-bench-security.sh -e check_2.6

Runs the full benchmark but explicitly excludes check 2.6 (TLS authentication).

Link
sudo ./docker-bench-security.sh -e check_4.5,check_5.1

Runs the full benchmark while excluding multiple specific checks defined by a comma-separated list.

Link
sudo ./docker-bench-security.sh -e docker_swarm_configuration

Runs the full benchmark but skips the entire Docker Swarm Configuration section.

Link

Image Filter1

sudo ./docker-bench-security.sh -t <image_tag>

Limits the container image checks to only images matching the specified tag.

Link

Container Execution Variants2

docker run --rm --net host --pid host --userns host --cap-add audit_control -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --label docker_bench_security docker/docker-bench-security -c host_configuration

Runs only the host configuration checks using the containerized version of the tool.

Link
docker run --rm --net host --pid host --userns host --cap-add audit_control -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --label docker_bench_security docker/docker-bench-security -e check_1.1

Runs the containerized benchmark excluding specific kernel capability checks.

Link

Environment Configuration2

export DOCKER_CONTENT_TRUST=1 && sudo ./docker-bench-security.sh

Enables Docker Content Trust in the shell before running the benchmark to satisfy DCT checks.

Link
sudo -E ./docker-bench-security.sh

Preserves existing environment variables (like proxy settings) when running the script as root.

Link

Logging and Auditing2

sudo ./docker-bench-security.sh -c check_1.2.1

Validates specifically if a separate partition for containers has been created.

Link
sudo ./docker-bench-security.sh -c check_2.12

Checks specifically if centralized and remote logging is configured for the Docker daemon.

Link

Access Control2

sudo ./docker-bench-security.sh -c check_2.13

Verifies that the Docker daemon performs live restoration to reduce downtime.

Link
sudo ./docker-bench-security.sh -c check_3.1,check_3.2

Audits the ownership and permissions of the docker.service and docker.socket files.

Link

Automation and Pipeline2

sudo ./docker-bench-security.sh -j | jq .

Pipes the JSON output to jq for immediate formatted validation in a terminal.

Link
sudo ./docker-bench-security.sh -j > docker-bench-results.json

Redirects JSON output to a file for ingestion by SIEM or dashboard tools.

Link

Advanced Filtering2

sudo ./docker-bench-security.sh -c host_configuration,container_runtime -e check_1.2

Combines inclusion and exclusion flags to audit host and runtime sections but skip disk partition checks.

Link
sudo ./docker-bench-security.sh -c check_4.1 -t production_image

Checks user creation within containers only for images tagged 'production_image'.

Link

Cloud Posture2

sudo ./docker-bench-security.sh -c check_2.4

Verifies that insecure registries are not allowed in the daemon configuration.

Link
sudo ./docker-bench-security.sh -c check_2.11

Ensures that Userland Proxy is disabled if hairpin NAT is available.

Link

Blue Team Validation4

sudo ./docker-bench-security.sh -c check_5.10

Verifies that memory usage limits are set for containers to prevent DoS attacks.

Link
sudo ./docker-bench-security.sh -c check_5.11

Verifies that CPU priority is set appropriately for containers.

Link
sudo ./docker-bench-security.sh -c check_5.12

Ensures the container's root filesystem is mounted as read-only.

Link
sudo ./docker-bench-security.sh -c check_5.31

Checks that the docker socket is not mounted inside any container.

Link

Compliance Auditing1

sudo ./docker-bench-security.sh -l /var/log/audit/docker_compliance_$(date +%F).log

Generates a timestamped compliance log file in a dedicated audit directory.

Link

Incident Response2

sudo ./docker-bench-security.sh -c check_5.25

Checks if container health checks are configured to detect compromised or stalled services.

Link
sudo ./docker-bench-security.sh -c check_2.15

Validates that User Namespace Remapping is enabled to mitigate privilege escalation attacks.

Link

Advanced Container Runtime1

docker run --rm --net host --pid host --userns host --cap-add audit_control -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --label docker_bench_security docker/docker-bench-security -j > report.json

Runs the containerized audit in a pipeline and saves JSON output to the host.

Link

CI/CD Integration2

sh -c 'sudo ./docker-bench-security.sh -j' | grep -q '"Warn": 0'

Pipeline check that fails if any warnings are detected in the JSON output.

Link
sh -c 'sudo ./docker-bench-security.sh -j' | grep -q '"Fail": 0'

Pipeline check that fails if any hard failures are detected in the JSON output.

Link

Advanced Customization1

sudo ./docker-bench-security.sh -b -l custom.log -c container_images -e check_4.6

Runs a customized audit on images, logging to a file, excluding health check validation.

Link

Legacy Compatibility1

sudo ./docker-bench-security.sh -c 1,2,3

Runs checks for sections 1, 2, and 3 using the older comma-separated integer syntax.

Link

Docker Rootless1

docker-bench-security.sh

Attempts to run the script without sudo, useful for verifying rootless docker configurations.

Link

Network Security2

sudo ./docker-bench-security.sh -c check_5.9

Checks if the container's network bridge is set to the default docker0.

Link
sudo ./docker-bench-security.sh -c check_2.6

Verifies that TLS authentication is configured for the Docker daemon.

Link

Cleanup1

rm docker-bench-security.log.json

Removes the default JSON log file generated by the tool after audit completion.

Link