hardMultiple ChoiceObjective-mapped
CAS-004 Prevent secrets in Docker images? Practice Question
An organization uses a CI/CD pipeline that builds Docker images and pushes them to a private registry. A security analyst discovers that some images contain environment variables with database credentials. Which of the following is the most effective way to prevent this in the future?
⚠ Common exam trap
Candidates often choose 'Use .dockerignore to exclude files' because it can prevent some files from being copied, but environment variables set via ENV or passed at build time are not files. Multi-stage builds address the root cause.
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
✓
Implement multi-stage builds to separate build and runtime environments.
The best approach is to use multi-stage builds: build the application in one stage, then copy only the artifact to a final, clean image. This avoids including build-time secrets in the final image. Additionally, using Docker BuildKit's --secret flag can inject secrets without persisting them.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a .dockerignore file to exclude credential files.
Why it's wrong here
.dockerignore prevents copying files but does not eliminate secrets set via ENV or build args.
- ✗
Scan images with a vulnerability scanner after build.
Why it's wrong here
Scanning detects known vulnerabilities, not embedded secrets.
- ✗
Reduce the base image size to minimize attack surface.
Why it's wrong here
Size reduction does not remove secrets already embedded.
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.
✓Implement multi-stage builds to separate build and runtime environments.Correct answer▾
✗Use a .dockerignore file to exclude credential files.Wrong answer — click to see why▾
Why this is wrong here
.dockerignore prevents copying files but does not eliminate secrets set via ENV or build args.
✗Scan images with a vulnerability scanner after build.Wrong answer — click to see why▾
Why this is wrong here
Scanning detects known vulnerabilities, not embedded secrets.
✗Reduce the base image size to minimize attack surface.Wrong answer — click to see why▾
Why this is wrong here
Size reduction does not remove secrets already embedded.
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?”
Go deeper
Related to this question
About these practice questions
This CAS-005 question is part of Courseiva's 968-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
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.