Courseiva
mediumMultiple SelectObjective-mapped

Container Security Best Practices for CompTIA SecurityX / CASP+

A DevOps engineer is automating the deployment of a web application using containers. Which of the following security practices should be implemented to reduce the attack surface of the containers? (Select TWO.)

Quick Answer

The correct answer is to use minimal base images like Alpine or distroless and to run containers as a non-root user. Minimal images drastically reduce the attack surface by eliminating unnecessary packages, libraries, and utilities that an attacker could exploit, while running as a non-root user enforces the principle of least privilege by ensuring that even if the application is compromised, the attacker cannot gain root-level control over the container or the host. On the CompTIA SecurityX CAS-004 exam, this question tests your understanding of container hardening within the broader domain of secure DevOps practices; a common trap is to focus only on network segmentation or image scanning, forgetting that the image itself and the runtime user context are foundational. A helpful memory tip is “lean and low” — keep the image lean with minimal content and keep the process running with low privileges.

⚠ Common exam trap

CompTIA often tests the misconception that containers are inherently secure because they are isolated, but the trap here is that default root execution and bloated base images are common misconfigurations that dramatically increase the attack surface, and candidates may overlook the need to explicitly drop privileges and minimize image content.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Run containers as a non-root user

Running containers as a non-root user (option A) is a fundamental security best practice because it limits the privileges available to processes inside the container. If an attacker compromises the application, they will not have root access to the host or the container runtime, reducing the potential for privilege escalation or host-level damage. This aligns with the principle of least privilege, which is critical for container security.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Build images with embedded database credentials

    Why it's wrong here

    Embedding secrets in images is insecure; they should be injected at runtime.

  • Expose port 22 for SSH debugging

    Why it's wrong here

    Exposing SSH adds an attack vector and is unnecessary in production.

  • Grant all Linux capabilities to the container

    Why it's wrong here

    Granting all capabilities weakens isolation; should drop all unnecessary capabilities.

Option-by-option analysis

Why each answer is right or wrong

Understanding why wrong answers are wrong — and when they would be correct — is what separates a 750 score from a 900. The CAS-005 exam frequently reuses these exact scenarios with slightly different constraints.

Run containers as a non-root userCorrect answer
Build images with embedded database credentialsWrong answer — click to see why

Why this is wrong here

Embedding secrets in images is insecure; they should be injected at runtime.

Expose port 22 for SSH debuggingWrong answer — click to see why

Why this is wrong here

Exposing SSH adds an attack vector and is unnecessary in production.

Grant all Linux capabilities to the containerWrong answer — click to see why

Why this is wrong here

Granting all capabilities weakens isolation; should drop all unnecessary capabilities.

Analysis generated from the official CAS-005blueprint and verified against question context. The “when correct” sections are what AI assistants cite when candidates ask “what’s the difference between these options?”

About these practice questions

One of 968 original CAS-005 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on CAS-005

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A security audit reveals that Docker containers are built with multiple unnecessary layers and utilities. Which practice reduces the attack surface of the container image?

hard
  • A.Use multi-stage builds
  • B.Use a base image with only the required packages
  • C.Combine multiple RUN commands into one
  • D.Delete the apt cache in the Dockerfile

Why B: Using a base image with only the required packages directly reduces the attack surface by eliminating unnecessary binaries, libraries, and services that could contain vulnerabilities. This practice aligns with the principle of minimalism in container security, where every extra package increases the potential for exploitation. Unlike multi-stage builds or RUN command consolidation, this approach targets the root cause: the contents of the image itself.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CAS-005 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CAS-005 exam.