Where do containers come from?

The cloud runs mostly containers because it's container technology that allows web sites and web apps to spawn fresh copies of themselves as demand increases. They're the reason hundreds of millions of people can use popular sites without those sites buckling under the pressure of global traffic. Containers are a Linux technology, meaning that they rely on code (specifically `cgroups` and namespaces) unique to the Linux kernel, so when you run a container, you're running Linux. Using container images from sites like quay.io and dockerhub.io, most people build new containers specific to their application or use case. But that makes some people wonder: if my container comes from a developer building on top of another developer's container, where do *those* containers come from? Don't worry, it's not turtles all the way down. You can build a container from scratch, and there's a great open source tool called

Buildah

to help you do it.

Container specifications

Containers grew out of projects like LXC and Docker, and it's the

Open Container Initiative (OCI)

that maintains the formal specification of what a container is. A properly assembled container that meets the OCI definition runs on any OCI-compliant container engine, such as Podman, Docker, CRI-O, and so on.

Installing Buildah

On Fedora and CentOS, you may have Buildah already installed. If not, you can install it with your package manager:

On Debian and Debian-based systems:

Configuring Buildah

Because Buildah creates containers, configuring your environment for it is the same as configuration for podman. Whether or not you're using podman,

configure your system for "rootless" podman

before continuing.

Building a container out of nothing

To build a brand-new container, using nobody's prior work as your foundation, you use the special name `scratch` to tell Buildah that you want to create an empty container. The `scratch` designation is not an image name, it's your exemption from using an existing image to base your work on.

This new container, named `working-container` by defalt, features a small amount of metadata and nothing else, and it's secretly running in the background now. You can see it with the `containers` subcommand:

To run the container, you must first use the `unshare` subcommand (unless you're running Buildah as root):

And confirm that your working container has no functionality:

Adding to your container

To add commands to your container, you must mount it first:

With the container mounted to your `~/.local` directory (or `/var/lib/containers/` in the case of running as root), you can add packages using your package manager. The `--releasever` must match the distribution you're running as you build the container.

The exact method of adding packages depends on your distribution and the package manager it uses. For example, on my Slackware desktop I use `installpkg`:

Now you can run the container and try something simple, like launching a shell:

Configuring your container

The `buildah config` subcommand gives you access to common attributes such as the default command you want your container to run when it's launched, set environment variables, set the default shell, define the author, architecture, and hostname, and much more.

Distributing your container

When you're finished constructing your container, you can preserve it as an image using the `commit` subcommand.

Build it with Buildah

Containers sometimes seem magical, but they're not magic. They're built from the ground up, and they're flexible enough that once an image exists, others can use it to build new containers and container images that fill a different niche. It's not necessary to start from scratch, but if you're curious how images start, or you want to try to create an image specific to your requirements, Buildah is the tool to use.

Proxied content from gemini://sdf.org/klaatu/geminifiles/buildah.gmi (external content)

Gemini request details:

Original URL
gemini://sdf.org/klaatu/geminifiles/buildah.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.