The DevOps Roadmap: 7 Containerization Best Practices

by | 15.02.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!

CommunityNew

The DevOps Awareness Program

Subscribe to the newsletter

Join 100+ cloud native ethusiasts

#wearep3r

Join the community Slack

Discuss all things Kubernetes, DevOps and Cloud Native

Related articles6

Startup speed, enterprise quality

Startup speed, enterprise quality

Liebe Kunden, Partner und Kollegen,2021 ist vorbei und uns alle erwarten neue Herausforderungen und Ziele in 2022.In den letzten 3 Jahren hat sich p3r von einer One-Man-Show zu einer festen Größe im deutschen Cloud-Sektor entwickelt. Mit inzwischen 11...

Introduction to GitOps

Introduction to GitOps

GitOps serves to make the process of development and operations more developer-centric. It applies DevOps practices with Git as a single source of truth for infrastructure automation and deployment, hence the name “Git Ops.” But before getting deeper into what is...

Kaniko: How Users Can Make The Best Use of Docker

Kaniko: How Users Can Make The Best Use of Docker

Whether you love or hate containers, there are only a handful of ways to work with them properly that ensures proper application use with Docker. While there do exist a handful of solutions on the web and on the cloud to deal with all the needs that come with running...

Cilium: A Beginner’s Guide To Improve Security

Cilium: A Beginner’s Guide To Improve Security

A continuation from the previous series on eBPF and security concerns; it cannot be reiterated enough number of times how important it is for developers to ensure the safety and security of their applications. With the ever expanding reach of cloud and software...

How to clean up disk space occupied by Docker images?

How to clean up disk space occupied by Docker images?

Docker has revolutionised containers even if they weren't the first to walk the path of containerisation. The ease and agility docker provide makes it the preferred engine to explore for any beginner or enterprise looking towards containers. The one problem most of...

Parsing Packages with Porter

Parsing Packages with Porter

Porter works as a containerized tool that helps users to package the elements of any existing application or codebase along with client tools, configuration resources and deployment logic in a single bundle. This bundle can be further moved, exported, shared and distributed with just simple commands.