Docker · Containers in practice
How do you secure a container image?
Short answer
Start from a minimal trusted base, pin digests, scan for vulnerabilities, sign and attest images, and rebuild regularly. Treat the image as a supply-chain artifact, not just a build output.
Image security covers what is inside the image, where it came from, and whether it has been tampered with. A scan at build time is necessary but not sufficient, because new CVEs are disclosed after the build.
trivy image --severity HIGH,CRITICAL api:1.0.0
cosign sign --key cosign.key registry.example.com/api@sha256:abc123
docker buildx imagetools inspect registry.example.com/api:1.0.0Controls that matter
- Pin base images by digest and rebuild on a schedule for patches
- Use a minimal base to reduce the package surface
- Run as non-root and drop unnecessary capabilities
- Generate an SBOM so you can answer what is inside the image
- Enforce a scan gate in CI and block critical findings with a documented exception process
- Verify signatures and digests at deploy time
A scanner reports known CVEs; it does not detect malware or a compromised upstream account. Provenance, signature verification and reproducible builds address different parts of the supply chain.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why is a build-time scan not enough?
- 2What does signing an image prove?
- 3How do you handle a critical CVE in a base image?
- 4What is an SBOM used for?
Say it in the interview
I treat images as supply-chain artifacts. I pin base images by digest, keep them minimal, scan the final image in CI, and rebuild regularly so patches actually reach production. I also sign images and generate an SBOM, then verify signatures at deploy time. A scan alone is not enough, because new vulnerabilities appear after the build.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.