Containers and buildpacks
Containers are a common concept in cloud infrastructure. In this document, we want to explain what containers are and why they are beneficial for your application. To do this, we will take a look at the most widely used containerization tool called Docker. We will also show how STACKIT Cloud Foundry can automatically containerize your application for you using buildpacks.
What are containers?
Section titled “What are containers?”Containers are executable instances of your application, packaged together with all dependencies required for execution. These loosely isolated environments are not only useful for the cloud but can also run on container runtimes on local machines or other more traditional configurations.
While virtual machines (VMs) virtualize the underlying infrastructure and therefore require a guest operating system, containers virtualize the operating system directly and thus only include the application and its dependencies. This makes containers very lightweight and portable. Since all dependencies of the application are packaged within the container, they are platform-independent.
Your application, packaged in a container and ready to be deployed, is called a container image. These images are easy to create and quick to start, which is why they are the backbone of any fast-scaling infrastructure.
With these advantages, containers support modern development techniques and architectures such as DevOps and microservices. Due to their small size, they improve CPU and memory utilization.
What are Docker images?
Section titled “What are Docker images?”The most widely used containerization tool is Docker. It is an open-source project supported by a company of the same name. It provides the containerization tools needed to package your application into container images, but also offers additional products in its ecosystem, such as the container registry Docker Hub, which serves as a repository for public (and private) container images, a desktop client with Docker Desktop, and more.
It provides a client and command-line tools and can automatically build images by reading instructions from a Dockerfile. However, this also means that for every application you want to containerize with Docker, you need to write such a file.
For more information about Docker and Docker images in general, see the official documentation.
What are buildpacks?
Section titled “What are buildpacks?”Buildpacks are a containerization method specifically developed for the Cloud Foundry platform, but they are also increasingly discussed in other cloud platform projects. In short, buildpacks can identify your application frameworks and dependencies and then package everything needed into a container image. Compared to Docker, you don’t even have to write instructions on how to containerize your application—buildpacks already know how to do it.
To achieve this, there are many buildpacks specialized for different frameworks, languages, and even dependencies. They typically consist of four scripts:
- detect determines whether a buildpack can be used for a given application type
- supply packages all dependencies required by the application
- finalize prepares the application for execution
- release provides information on exactly how the application should be run
The execution of these scripts is called staging. The result of staging is called a droplet and works just like any other container image.
When a build artifact is pushed to a Cloud Foundry platform (such as STACKIT Cloud Foundry), the platform goes through the detection phase of its buildpacks (or uses the buildpack predefined via an argument in the push command/manifest file). The first buildpack with a successful detect run is then used to create a droplet. After this staging process, the droplet can be deployed and run on the internal container runtime.
If you define the buildpack to be used by the platform in the push argument or in the manifest file, you can also use custom buildpacks from the open source community or create your own custom buildpack.
With buildpacks, you can delegate the effort of scripting and containerizing your application’s build artifact directly to the cloud platform where you want to publish your application.
For more information about buildpacks, see the official Cloud Foundry documentation on buildpacks.