Skip to content

Apple Container Machine — Fast, Lightweight Linux Environments on Mac

Source: Apple Container Machine Documentation \ Source/Org: Apple (GitHub — container project)


TL;DR

Apple's open-source container-machine provides an integrated Linux environment on macOS that is fast, lightweight, and persistent. Unlike traditional Docker-style containers designed to run a single application, container-machine is modeled after a complete Linux environment — it boots the image's init system (systemd), auto-maps the host username and home directory, and provides a seamless shell experience. The quickstart is straightforward: container machine run opens a shell or runs a single command. It supports custom images (any Linux distribution with /sbin/init), configurable resources (CPUs, memory), and flexible home-directory mounting (read-write, read-only, or none). Each container has an alias m for convenient command invocation: m ls, m run, etc.

What Makes It Different

Container-machine is not a Docker competitor. It serves a different use case: Linux development environments on Mac. Where Docker optimizes for running isolated application processes in production-like environments, container-machine optimizes for the developer experience of working inside a Linux environment on a Mac host.

Key differences from traditional container approaches:

Aspect Docker Container Container Machine
Model Application isolation Full Linux environment
Init system Usually none Runs systemd
User mapping Manual or root Auto-maps host username
Home directory Separate volume Auto-mounted from host
Persistence Opt-in volumes Persistent by default
Primary use case Deployment / CI Local development

Quickstart

The basic usage is remarkably simple:

container machine run

This command: 1. Pulls or finds the default container image 2. Boots the image with systemd as init 3. Creates a user matching your host username 4. Maps your host home directory into the container 5. Drops you into a shell

To run a single command instead of opening a shell:

container machine run -- echo "hello from linux"

Custom Images

Container-machine supports any Linux distribution that includes /sbin/init. This means you can run Fedora, Debian, Ubuntu, Arch Linux, or any other systemd-based distribution. The image must meet a minimal requirement: it must be capable of booting its init system and creating a user on first boot.

Apple provides a built-in setup script that runs on first boot to create the user and configure the environment. This script is customizable via /etc/machine/create-user.sh inside the container image — image builders can substitute their own provisioning logic.

Configuration and Resource Management

Container-machine supports a configuration system for tailoring the environment:

  • CPU allocation: Resize the number of CPUs available to the container machine
  • Memory allocation: Set the memory limit for the Linux environment
  • Home directory mount mode: Configure how the host home directory appears inside the container:
  • rw (read-write) — changes in the container affect the host
  • ro (read-only) — the container can read but not modify host files
  • none — no home directory mount; the container has its own isolated filesystem

The m Alias

All container-machine commands are available under the shorthand m:

m ls          # list container machines
m run         # start and enter a container machine
m stop        # stop a running container machine
# etc.

This makes it ergonomic for daily development workflows where you frequently drop into a Linux environment.

Why Apple Built This

Apple's motivation is straightforward: many developers targeting servers, cloud infrastructure, or Linux-based toolchains need a Linux environment for development. The traditional solutions — dual-booting, running a Linux VM, or using Docker — each have significant friction points. Container-machine aims to provide a Linux environment that feels as native as macOS itself: fast to start, integrated with the host filesystem, and persistent across sessions.

It represents a bet on developer experience as the key differentiator for Apple's platform — making macOS the best machine for developing software that runs on Linux.

Key Takeaways

  1. Apple's container-machine provides fast, lightweight, and persistent Linux environments on Mac — modeled as full environments, not application containers.
  2. It boots the image's init system (systemd) and auto-maps the host username and home directory for a seamless experience.
  3. The quickstart is a single command (container machine run) that opens a shell or runs a specific command.
  4. Custom images are supported — any Linux distribution with /sbin/init. A built-in setup script handles first-boot provisioning.
  5. Configuration options include CPU/memory resizing and home-directory mount mode (rw/ro/none).
  6. All commands have a shorthand m alias for ergonomic daily use.
  7. It optimizes for developer experience — making macOS the best platform for Linux-targeted development.