The DevOps Roadmap: 7 Containerization Best Practices

by | Feb 15, 2021 | Engineering

Containers have the opportunity for developers to build predictable environments isolated from other applications. The application’s software dependencies can also be bundled in containers, such as particular versions of programming language runtimes and other software libraries. Apart from these reasons, several other reasons make containers a preferable option when you think of your cloud-native strategy.

Learn more about containers here!

As we went around, Containerization makes our life more comfortable, and to make your dev life a bit easier, following the best practices is one way to start.

In this post, we will go around few best practices in the industry and reasons you should consider these practices when you start or are in the middle of your cloud-native journey.

The list is not in any order of priority. Feel free to experiment or adapt any/all!

Choose Container Engine Properly

Choose the right container engine for your application based on the project and use cases; if you are not sure what the right container engine for your application would be, then it is good to go with the most common and popular one, i.e., Docker.

But don’t just choose Docker because someone says it, do your own analysis, and then select the right one for your project. Careful consideration helps you to minimize technical debt.

Keep Container Image Small

It’s generally preferable to have a small Docker Image, everyone agrees. To Keep images smaller:

  • Use multi-stage builds (e.g. docker multi-stage build)
  • Use smaller base image
  • Avoid storing application data in your container’s writable layer. This is less efficient from an I/O perspective than using volumes or bind mounts, instead of storing data in external data storage (e.g. volumes in docker.) Also, this increases the size of your container.
  • When building images, make sure that image only contain the appropriate packages, delete what is not required and always tag the image. The actual application output would be affected by running several processes within a single container, so build multiple containers for an application that can communicate with each other instead.

Single App per Container

You can run several, but running a single app per container is a great practice. Each of your containers should contain just one app since a container is built to have the same lifecycle as the app it hosts. So when a container starts and stops so should the app start and stop.

Use Trusted/Secure Images

Try to use verified images while you deploy your container and if you need to use an unverified image scan it well, so any vulnerability doesn’t creep into your application. Scan for vulnerability in images/packages/dependencies and if found, fix it and also don’t forget to keep searching for newer vulnerabilities regularly.

Don’t store secrets in simple text

Never store in plain text secrets/sensitive files containing content such as DB username/passwords or any other sensitive credentials or tokens, use native secret management software in the container engine or use powerful external plugins instead.

Never Run Container as Root

Because of security issues, never run a container as root. As if the container will have root access, any security flow in any package/dependencies installed will affect the original host system.

Monitor Your Containers

It is best practice to regularly and automatically track your containers, check how they work, collect CPU, RAM, I/O usage and other resource data, and also collect and review logs from time to time. While debugging or monitoring this data would be very helpful.

Few tools that can help you to monitor:

Final Thoughts⭐

I hope you went through all of these practices and are ready to create a better containerization environment for your organization.

One pro tip: Try using any CI/CD pipeline to automatically build, tag images, test and deploy containers when you check a change to the source control or create a pull request.

If you’d like to explore more best practices for your cloud-native journey, we have put an excellent blog discussing best practices for your CI/CD.

Read it here!

Happy Experimentation!

Explore more

Serverless, FaaS and why do you need them?

In recent years, serverless adoption has started, with more and more individuals depending on serverless technology to meet organizations’ specific needs. A survey conducted by Serverless Inc showed in 2018 that half of the respondents used serverless in their job,...

read more

The DevOps Roadmap: Unikernels

Containerization is one of the core building principles of clouds and DevOps, but traditional VMs and containers lack the security and agility that modern infrastructure craves. We are moving towards workloads that are smaller, faster, and more secure than the...

read more

The DevOps Roadmap: Virtualization

The Full-Stack Developer's Roadmap Part 1: FrontendThe Full-Stack Developer's Roadmap Part 2: BackendThe Full-Stack Developer's Roadmap Part 3: DatabasesThe Full-Stack Developer's Roadmap Part 4: APIsThe DevOps Roadmap: Fundamentals with CI/CDThe DevOps Roadmap: 7...

read more

Cloud Computing models: SaaS vs IaaS vs PaaS

Companies embrace cloud computing worldwide, and the forecasted size of 1025.9 billion USD by 2026 says the same story. Owning and managing infrastructure comes with a considerable cost and improper utilization of human resources. Companies are meant to foster...

read more

What is Cloud Computing?

"Cloud Computing" describes a set of terms that you hear everywhere nowadays. It might be in your morning newspaper, or the cool kid you know talks about it with few jargon terms like scalability, elasticity, etc. and now you want to know about these terms. I might...

read more

Interested in what we do? Looking for help? Wanna talk about software strategy?