VOOZH about

URL: https://thenewstack.io/3-best-practices-for-image-building-and-scanning/

⇱ 3 Best Practices for Image Building and Scanning - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-07-26 07:32:27
3 Best Practices for Image Building and Scanning
contributed,sponsor-tigera,sponsored,sponsored-post-contributed,
Containers / Security

3 Best Practices for Image Building and Scanning

By following best practices for image building and scanning, you can help ensure the security of the containers and workloads in your environment.
Jul 26th, 2022 7:32am by Amit Gupta
👁 Featued image for: 3 Best Practices for Image Building and Scanning
Feature image via Pixabay.
Tigera sponsored this post. Insight Partners is an investor in Tigera and TNS.
Amit Gupta
Amit is chief product officer at Tigera where he is responsible for the strategy and vision of Tigera’s products and leads the delivery of the company’s roadmap. Amit is a hands-on product executive with expertise in building software products and services across various domains including cloud security, cloud native applications, and public and private cloud infrastructure.

As enterprises adopt containers, microservices and Kubernetes for cloud native applications, vulnerability management is crucial to improve the security posture of containerized workloads throughout build, deployment and runtime.

Securing your build artifacts and deployment pipeline, especially when it comes to images, is extremely important.

By following best practices for image building and scanning throughout the application development and deployment process, you can help ensure the security of the containers and workloads in your environment.

Let’s look at some of the nuances of choosing a base image, hardening your container image and container image scanning, including tips on choosing an appropriate scanning solution and tackling privacy concerns.

Choose an Appropriate Base Image

It’s important to choose a base image that reduces the attack surface of your container. I recommend using a distroless or scratch image because they contain only the application and its runtime dependencies. Both types of images improve your security posture by reducing the attack surface and exposure to vulnerabilities.

If for some reason you can’t use a distroless or scratch image, choose a minimal distro. Modern immutable Linux distributions, such as Bottlerocket and Flatcar Container Linux, can be used as base images for containers, as can minimal versions of traditional Linux distributions such as Ubuntu, Red Hat or Alpine. While a minimal image will work, keep in mind that this type of image does not protect against vulnerabilities in operating system (OS) packages in the OS.

Tigera provides Calico, a unified network security and observability platform to prevent, detect and mitigate security breaches in Kubernetes clusters. Tigera’s open-source offering, Calico Open Source, is the most widely adopted container networking and security solution.
Learn More
The latest from Tigera

Harden Your Container Image

Container image hardening adds defensive layers that allow you to run applications securely within a container, while also reducing security weaknesses and the attack surface. Building hardened container images for workloads is important because nonhardened images open up your workloads to a range of risks, including disclosure of information and privilege escalation to the container host.

Here are a few ways to harden container images.

  • Use base images from trusted sources only, for example, the official Ubuntu or Red Hat release channel.
  • Double-check an image’s hash against released information, even if it’s from a trusted source. It’s not that difficult for an attacker to embed malicious code in a base image, and then make the image available on a repository such as Docker Hub.
  • Minimize your base images. They should only contain an application’s runtime dependencies.
  • Run containers with the minimum necessary permissions, following the principle of least privilege ( run containers as non-root when possible). This way, it will be more difficult for attackers to escape the container, as happened with the CVE-2020-15257 vulnerability.
  • Verify the image using container image signing. While Kubernetes does not natively include a container image verification tool, you can use Docker Notary to sign images and verify an image signature using the Kubernetes admission controller.

If using a Docker image, I recommend the following:

  • Do not use tags: Tags (for instance mutable tags like latest or master) can cause application stability issues if a dependent library is moved or changed. They can also cause issues with image scanning in your CI/CD pipeline, since they are regularly updated with features and fixes. Instead of using tags, pin the base image version in the Dockerfile (such as ubuntu:20.08).
  • Compress layers into one single layer: Layers show development history and can reveal sensitive information. Because container images built with Docker tend to include multiple layers, you should use a multistage build or `option–squash` (an experimental Docker daemon available in Docker API 1.25+) to compress existing layers.

Scan Your Container Image

Container image scanning helps determine if there are vulnerable components present in an image by examining a container’s filesystem and metadata and then comparing the collected data against vulnerability information from various trusted sources, such as National Vulnerability Database or private intelligence sources. There are plenty of scanning tools available, both open source and commercial.

You want to make sure that your image-scanning tool scans all OS packages in your container image, and that it understands the language(s) used by your application so that it can scan application dependencies. A good container image-scanning tool should also:

  • Detect sensitive files, such as certificates and passwords, that exist in the filesystem
  • Scan binaries (such as .elf or .exe)
  • Integrate into your CI/CD system
  • Have a low false-positive rate. (Note that both false positives and negatives are to be expected during container image scanning; your application and security teams will need to analyze these and assess risk.)

While many public cloud providers and container registry service providers offer image and container scanning services, a lot of them don’t scan application dependencies and only support a limited number of OS versions.

Since information about security vulnerabilities in your product is sensitive data that would become a big liability in the wrong hands, don’t forget to address data security and privacy concerns before choosing a scanning tool. It’s important to understand what data a scanning tool will collect, and how, in order to understand the risk of data exposure. For example: Does it collect package metadata only, or will it upload your container image to its SaaS service?

To ensure the tool meets guidelines set by your security and/or compliance teams, you also need to determine whether the tool will store collected data on-premises or in the cloud as part of a SaaS. Be sure to check the contract, if using a commercial tool, to understand what kind of clauses are in place for damages in the case of a data breach, or the documentation, if using an open-source tool, to understand the risk of a data leak.

Summary

The tips and best practices included in this article serve as a good starting point for vulnerability management. I recommend reading Chapter 3 of “Kubernetes Security and Observability: A Holistic Approach to Securing Containers and Cloud-Native Applications,” an O’Reilly book I helped author, to learn about these best practices in further detail and to discover more.

Laura Ferguson contributed to this article.

Tigera provides Calico, a unified network security and observability platform to prevent, detect and mitigate security breaches in Kubernetes clusters. Tigera’s open-source offering, Calico Open Source, is the most widely adopted container networking and security solution.
Learn More
The latest from Tigera
TRENDING STORIES
Amit Gupta is chief product officer at Tigera where he is responsible for the strategy and vision of Tigera’s products and leads the delivery of the company’s roadmap. Amit is a hands-on product executive with expertise in building software products...
Read more from Amit Gupta
Tigera sponsored this post. Insight Partners is an investor in Tigera and TNS.
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Tigera, Pragma, Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.