What is container image scanning, and where should it happen?
BeginnerConceptSecurity basics for DevOps
Answer
In one line: Container image scanning checks the OS packages and application libraries inside an image for known vulnerabilities, misconfigurations and secrets — and it should happen in the pipeline, in the registry and continuously after deployment.
What scanners look for:
- Vulnerable OS packages (for example an old OpenSSL in the base image).
- Vulnerable application dependencies (npm, pip, Maven, Go modules).
- Embedded secrets (keys accidentally copied into the image).
- Misconfigurations — running as root, no healthcheck,
latestbase image. - Licence issues.
Tools: Trivy, Grype, Docker Scout, Snyk Container, Clair, AWS ECR scanning (with Inspector), Microsoft Defender for Containers, Harbor's built-in scanner.
Where to scan (defence in depth):
- In the CI pipeline — right after
docker buildand before pushing; fail the build on critical issues.docker build -t orders:${GIT_SHA} . trivy image --severity CRITICAL --exit-code 1 orders:${GIT_SHA} docker push orders:${GIT_SHA} - In the registry — scan on push, and re-scan regularly, because new CVEs are published for images that haven't changed.
- At deploy time — admission controllers (Kyverno, OPA Gatekeeper) can block images that weren't scanned or signed, or that come from untrusted registries.
- In running clusters — tools like Trivy Operator report vulnerabilities in workloads that are already running.
Reducing findings:
- Use minimal base images (distroless, Alpine, slim, Chainguard).
- Multi-stage builds so build tools aren't in the final image.
- Rebuild images regularly to get patched base layers.
- Generate an SBOM for each image so you can quickly check if you're affected by a new CVE.
Tip for interviews: mention "scan in CI, scan in the registry, enforce at admission and keep re-scanning" — it shows you know vulnerabilities appear after build time too.
More on Security basics for DevOps
What is the principle of least privilege?BeginnerWhat is SAST, DAST and SCA?BeginnerWhat is a CVE, and how do you handle vulnerabilities found by scanners?BeginnerWhat is software supply chain security (SBOM, image signing, SLSA)?IntermediateWhat is secrets management, and why shouldn't secrets be in code?BeginnerWhat is encryption in transit and encryption at rest?Beginner