Blog
No Runtime Required: Get Containers on macOS and Windows with Colima and Flox
Steve Swoyer | 13 December 2024
Fun Package Fridays is a series where we ask members of the Flox team to share fun and perhaps not-so-well-known tools and utilities you can find in the Flox Catalog, powered by Nix. Today's edition comes from Steve Swoyer, our staff writer and resident Nix abecedarian.
12 days from today, many of us expect to be inundated with plenty of packages.
So think of this week’s edition of Fun Package Friday(R)(TM) as kicking off the 12 Days of Christmas.
For this Friday, December 13th (!) we’re serving up a timely apotropaic talisman in the form of a neat, useful, powerful package that promises to revolutionize your workflow.
And with this as prelude, we give you...Colima, a lightweight Linux VM pre-configured for running containers on macOS, Linux, and Windows with WSL2.
Short for “Containers on Lima,” Colima is built on Lima, a CNCF-sponsored project for running Linux VMs on macOS. It ships pre-configured with Docker Engine by default, but it can also be set up to run just containerd. Colima is an especially attractive option for running containers on macOS, integrating quite nicely with macOS’ Apple Hypervisor Framework.
Colima = containers made simple
Flox does this thing where we point out stuff you can do with us that you can’t do with containers.
But the reverse of this shtik is also true. Flox, Nix, and containers are all gifts to the world. They let you do different kinds of things differently. Need to run software in a hermetically isolated context but with direct access to local hardware? Containers are great for that! (On Linux, at least.) Need a way to package up a runtime environment into a portable build artifact for deployment to a managed K8s service or a serverless environment like AWS Lambda? Containers are great for this, too!
But not everyone wants to install a resource-intensive container runtime, especially on desktop platforms like macOS and Windows.
If you find yourself nodding along thinking “Yep. I’m one of those people,” Colima is all you need.
Getting It
Let’s first install Flox. If you don’t already have Flox on your system, we’ve made it pretty easy to download, install, and play along at home.
Next, let’s grab Flox’s pre-built Colima example environment. This is shockingly simple:
This creates a local copy of the remote Flox environment colima
, activates it (with the -r
switch, for “remote”), starts the colima
service (with the -s
switch, for “services”), and puts you in a Flox subshell. When you type exit to quit (or press CTRL + D), this environment disappears and Colima shuts down.
Because Colima needs to spin up a Linux VM with Docker Engine, we do need to give it a moment, even after we see this message. (Moves fingers over keyboard for 30 seconds.) Okay. That should do it.
Note: If you want to bootstrap this yourself, you need to run flox install colima
to install it manually.
You’d then need to define a service so Flox knows to start and manage Colima. Just open up the manifest.toml
file that lives in .flox/env/
inside your project directory. Look for the [services]
section, and add the following:
Save and exit, then start your local Flox Colima environment using the -s
switch:
You won’t see the welcome message I showed above because you haven’t created logic to display it. 😄
Using it
Let’s suppose I’m containerizing DuckDB because I want to build a Flask-based app that exposes RESTful endpoints for users to interact with it. I’m using an Amazon Linux base image, because that’s what my (hypothetical) org runs in both its AWS Elastic Container Service and Elastic Kubernetes Service deployments.
First, I need to pull my container image from the AWS Elastic Container Registry. But let’s assume I’ve already done that. The next step is building my custom container image using the Dockerfile I’ve created.
Colima spins up a lightweight Linux VM that's configured by default to use Docker Engine. This means I’ve also got to install a Docker client so I can interact with it. My Flox colima
example environment already includes this:
(Note: If you’re playing along at home and bootstrapping from scratch, just run flox install docker-client
.)
Now that I’ve got my Docker client, let’s build my container:
Alll right. Now I’m ready to fire up and run my container in Colima:
Success! A quick double-check confirms that my container is, in fact, running:
It’s one thing to start a container, another to confirm it’s running, and still another to interact with it.
So let’s interact with. Let’s see if it behaves like a RESTful service running in a container should.
So it’s up, it’s running, and it’s accessible. But can I do the stuff I expect to able to do with it?
Even though I can't change that task's status to true
, I’m going to go ahead and call this a successful q.e.d.!
This has been Fun Package Friday(R)(TM)
So that’s Colima. It gives you a simple, lighter-weight VM for running containers on macOS and Windows with WSL. (Colima runs just fine on Linux, too—witness this walk-through!—albeit with one caveat: instead of running natively, your containers run inside a VM.)
Colima is full-stop amazing on its own. But Flox makes it even, um, amazing-er, giving you an easy way to create and share a portable Colima environment for running containers … anywhere. Don’t believe me? Go ahead and flox activate -s -r flox/colima
on your system and take it for a spin.
Happy hacking!
Thanks to both Rok Garbas and Ross Turk for building this Colima environment! Collectively, Rok and Ross are Flox’s skunkworks platform engineering team. I’d be verklempt without ‘em!