Bird
Raised Fist0
Dockerdevops~5 mins

Security benchmarks (CIS Docker) - Commands & Configuration

Choose your learning style10 modes available
Introduction
Security benchmarks help you keep your Docker containers safe by following best practices. The CIS Docker benchmark is a guide that shows how to configure Docker securely to avoid common risks.
When you want to make sure your Docker containers do not have security holes.
When you need to audit your Docker setup for compliance with security standards.
When you want to reduce the risk of attackers exploiting your Docker environment.
When you are deploying Docker containers in production and want to follow best security practices.
When you want to learn how to configure Docker daemon and containers safely.
Commands
This command shows detailed information about your Docker installation, including security settings and runtime details.
Terminal
docker info
Expected OutputExpected
Client: Context: default Debug Mode: false Server: Containers: 3 Running: 1 Paused: 0 Stopped: 2 Images: 5 Server Version: 24.0.2 Storage Driver: overlay2 Logging Driver: json-file Cgroup Driver: cgroupfs Security Options: seccomp apparmor Kernel Version: 5.15.0-70-generic Operating System: Ubuntu 22.04.2 LTS OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 7.7GiB
This command runs the official Docker Bench Security script as a container. It checks your Docker host and containers against the CIS Docker benchmark rules.
Terminal
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/bench docker/docker-bench-security
Expected OutputExpected
Docker Bench for Security ========================= [INFO] 1 - Host Configuration [PASS] 1.1 - Ensure a separate partition for containers has been created [WARN] 1.2 - Ensure that Docker is using a supported storage driver [INFO] 2 - Docker Daemon Configuration [PASS] 2.1 - Ensure that Docker daemon is started with a user namespace [FAIL] 2.2 - Ensure that the Docker daemon is configured to use TLS ... Summary: Passed: 15 Warnings: 3 Failed: 2
→
-v /var/run/docker.sock:/var/run/docker.sock - Gives the container access to the Docker daemon to inspect the host.
→
--rm - Removes the container after the scan finishes.
This command lists running containers and shows their security options to check if they have extra protections like seccomp or AppArmor profiles.
Terminal
docker ps --quiet --filter 'status=running' | xargs -n 1 docker inspect --format '{{.Name}}: SecurityOpts={{.HostConfig.SecurityOpt}}'
Expected OutputExpected
/my-app: SecurityOpts=[seccomp=default] /my-db: SecurityOpts=[]
→
--filter 'status=running' - Filters to only running containers.
Key Concept

If you remember nothing else from this pattern, remember: running automated CIS benchmark checks helps you find and fix Docker security issues quickly.

Common Mistakes
Running Docker containers without any security options like seccomp or AppArmor.
This leaves containers more exposed to attacks and privilege escalations.
Always configure containers with appropriate security profiles and verify with docker inspect.
Ignoring warnings and failures from the Docker Bench Security scan.
Warnings and failures indicate real security risks that can be exploited.
Review and fix all warnings and failures reported by the benchmark scan.
Running the Docker Bench Security script without mounting the Docker socket.
The script cannot inspect the Docker host or containers without access to the Docker daemon.
Always mount /var/run/docker.sock inside the container when running the benchmark.
Summary
Use 'docker info' to check your Docker environment and security settings.
Run the Docker Bench Security container to scan your Docker host against CIS benchmarks.
Inspect running containers' security options to ensure they have proper protections.

Practice

(1/5)
1. What is the main purpose of the CIS Docker Security Benchmark?
easy
A. To provide guidelines for securing Docker containers
B. To speed up Docker container startup time
C. To increase Docker image size for better performance
D. To automate Docker container deployment

Solution

  1. Step 1: Understand CIS Docker Benchmark purpose

    The CIS Docker Security Benchmark is designed to help users secure Docker containers by providing best practice guidelines.
  2. Step 2: Compare options with purpose

    Options B, C, and D relate to performance or automation, not security guidelines.
  3. Final Answer:

    To provide guidelines for securing Docker containers -> Option A
  4. Quick Check:

    Security guidelines = A [OK]
Hint: CIS benchmarks focus on security rules and best practices [OK]
Common Mistakes:
  • Confusing security with performance improvements
  • Thinking CIS automates deployment
  • Assuming CIS increases image size
2. Which command runs the Docker Bench Security script to check your Docker host against CIS benchmarks?
easy
A. docker bench run security
B. docker run --rm -it docker/docker-bench-security
C. docker security scan bench
D. docker run bench-security

Solution

  1. Step 1: Recall the official Docker Bench Security command

    The correct command is to run the official Docker image with docker run --rm -it docker/docker-bench-security.
  2. Step 2: Check other options for syntax errors or invalid commands

    Options B, C, and D are not valid Docker commands or do not match the official usage.
  3. Final Answer:

    docker run --rm -it docker/docker-bench-security -> Option B
  4. Quick Check:

    Official Docker Bench command = A [OK]
Hint: Use official Docker image with docker run --rm -it [OK]
Common Mistakes:
  • Using incorrect or incomplete docker run syntax
  • Assuming 'docker bench' is a built-in command
  • Mixing up command order or flags
3. After running Docker Bench Security, you see this output line:
[WARN] 4.1 - Ensure that containers are not running in privileged mode
What does this warning mean?
medium
A. Containers are using too much CPU
B. Containers are missing network access
C. Containers are running with extra permissions that can be risky
D. Containers are not logging output

Solution

  1. Step 1: Understand privileged mode in Docker

    Privileged mode gives containers extended permissions on the host, which can be a security risk.
  2. Step 2: Interpret the warning message

    The warning indicates containers are running with these risky extra permissions.
  3. Final Answer:

    Containers are running with extra permissions that can be risky -> Option C
  4. Quick Check:

    Privileged mode risk = C [OK]
Hint: Privileged mode means extra risky permissions [OK]
Common Mistakes:
  • Confusing privileged mode with resource usage
  • Thinking it relates to network or logging
  • Ignoring security implications of privileged mode
4. You ran Docker Bench Security and got this error:
ERROR: 5.1 - Ensure Docker daemon is configured to use user namespaces: Not configured
How can you fix this issue?
medium
A. Restart Docker containers without changes
B. Remove all Docker images and rebuild
C. Increase Docker daemon CPU limits
D. Enable user namespaces in the Docker daemon configuration file

Solution

  1. Step 1: Understand user namespaces in Docker

    User namespaces isolate container users from host users, improving security.
  2. Step 2: Fix the error by enabling user namespaces

    This requires editing the Docker daemon config (e.g., /etc/docker/daemon.json) to enable user namespaces and restarting Docker.
  3. Final Answer:

    Enable user namespaces in the Docker daemon configuration file -> Option D
  4. Quick Check:

    User namespaces fix = B [OK]
Hint: Enable user namespaces in daemon config to fix error [OK]
Common Mistakes:
  • Restarting containers without config changes
  • Changing CPU limits unrelated to namespaces
  • Deleting images instead of fixing config
5. You want to improve your Docker host security by applying CIS Docker Benchmark recommendations. Which combination of actions is best?
hard
A. Run Docker Bench Security regularly, fix warnings, and restrict container privileges
B. Only update Docker to the latest version and ignore warnings
C. Disable Docker logging to improve performance and skip scans
D. Run containers as root for easier management and skip security checks

Solution

  1. Step 1: Identify best practices from CIS Docker Benchmark

    Regular scanning, fixing warnings, and limiting container privileges are key security steps.
  2. Step 2: Evaluate other options for security risks

    Options A, B, and C ignore warnings or increase risks by disabling logs or running as root.
  3. Final Answer:

    Run Docker Bench Security regularly, fix warnings, and restrict container privileges -> Option A
  4. Quick Check:

    Regular scans + fixes + least privilege = D [OK]
Hint: Scan often, fix issues, and limit privileges for best security [OK]
Common Mistakes:
  • Ignoring warnings thinking updates are enough
  • Disabling logs reduces visibility and security
  • Running containers as root increases risk
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard