Skip to main content

Requirements

To build the container project, you need:
There is a bug in the vmnet framework on macOS 26 that causes network creation to fail if the container helper applications are located under your Documents or Desktop directories. If you use make install, you can simply run the container binary in /usr/local. If you prefer to use the binaries that make all creates in your project bin and libexec directories, locate your project elsewhere, such as ~/projects/container, until this issue is resolved.

Compile and test

Build container and the background services from source, and run basic and integration tests:
make all test integration

Install locally

Copy the binaries to /usr/local/bin and /usr/local/libexec (requires entering an administrator password):
make install

Release build

To install a release build, with better performance than the debug build:
BUILD_CONFIGURATION=release make all test integration
BUILD_CONFIGURATION=release make install
Release builds include optimizations that significantly improve runtime performance. Use release builds for performance testing and production use.

Compile protobufs

container uses gRPC to communicate to the builder virtual machine that creates images from Dockerfiles, and depends on specific versions of grpc-swift and swift-protobuf. If you make changes to the gRPC APIs in the container-builder-shim project, install the tools and re-generate the gRPC code in this project using:
make protos

Develop using a local copy of Containerization

To make changes to container that require changes to the Containerization project, or vice versa:
1

Clone Containerization repository

Clone the Containerization repository such that it sits next to your clone of the container repository. Ensure that you follow containerization instructions to prepare your build environment.
2

Navigate to container directory

In your development shell, go to the container project directory:
cd container
3

Stop running services

If the container services are already running, stop them:
bin/container system stop
4

Configure local dependency

Reconfigure the Swift project to use your local containerization package and update your Package.resolved file:
/usr/bin/swift package edit --path ../containerization containerization
/usr/bin/swift package update containerization
5

Update init filesystem (optional)

If you want container to use any changes you made in the vminit subproject of Containerization, update the system property to use the locally built init filesystem image:
container system property set image.init vminit:latest
6

Build container

Build the project:
make clean all
7

Restart services

Restart the container services:
bin/container system stop
bin/container system start
If you are using Xcode, do not run swift package edit. Instead, temporarily modify Package.swift to replace the versioned containerization dependency:
.package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
with the local path dependency:
.package(path: "../containerization"),
Note: If you have already run swift package edit, whether intentionally or by accident, follow the steps in the next section to restore the normal containerization dependency. Otherwise, the modified Package.swift file will not work, and the project may fail to build.

Revert to normal dependency

To revert to using the Containerization dependency from your Package.swift:
1

Revert init filesystem property

If you were using the local init filesystem, revert the system property to its default value:
container system property clear image.init
2

Restore dependency

Use the Swift package manager to restore the normal containerization dependency and update your Package.resolved file. If you are using Xcode, revert your Package.swift change instead of using swift package unedit:
/usr/bin/swift package unedit containerization
/usr/bin/swift package update containerization
3

Rebuild

Rebuild container:
make clean all
4

Restart services

Restart the container services:
bin/container system stop
bin/container system start

Develop using a local copy of container-builder-shim

To test changes that require the container-builder-shim project:
1

Clone and modify

Clone the container-builder-shim repository and navigate to its directory. Make your necessary changes.
2

Build custom builder image

Build the custom builder image, set it as the active builder image, and remove the existing buildkit container so the new image will be used:
container build -t builder .
container system property set image.builder builder:latest
container rm -f buildkit
3

Test your changes

Run the container build as usual:
container build ...
If your modified builder image is broken, make sure to rebuild and correctly tag the builder image before attempting to build container-builder-shim again.

Build docs developers (and LLMs) love