On macOS, Docker Desktop is a very popular choice, but it is not the only option. If you don’t want to use Docker Desktop, or you are looking for a more lightweight alternative, Colima is a solid choice. Colima is a container runtime management tool for macOS and Linux that offers a minimal setup process while supporting multiple container runtimes, including Docker and Kubernetes. This article will show you how to use Colima to enable Docker and Docker BuildKit so that you can do container development efficiently without relying on Docker Desktop.
1. Introduction to Colima
Colima is an open-source project designed to provide a lightweight container runtime environment for macOS and Linux, supporting both Intel and Apple Silicon architectures. It has the following features:
- Simple, easy-to-use CLI: Colima provides a clean command-line interface, allowing users to quickly start and manage containers with simple commands.
- Automatic port forwarding: There is no need to manually configure port mappings; Colima handles them automatically.
- Support for multiple container runtimes: In addition to Docker, it also supports Containerd, Incus, and Kubernetes.
- Multi-instance support: You can run multiple container instances at the same time to meet different development needs.
The Colima GitHub repository is at https://github.com/abiosoft/colima, where you can find more detailed information.
2. Installing Colima and Docker
1. Install Colima
Colima supports several installation methods, and Homebrew is the most recommended. Open a terminal and run the following command:
brew install colimaIf you want to use the latest version, you can install the development branch:
brew install --HEAD colima2. Install Docker
Colima relies on the Docker client to interact with the container runtime. Install Docker via Homebrew:
brew install dockerAfter installation, the Docker client environment variables are configured automatically, so no additional setup is needed.
3. Starting the Docker Environment
Once installed, you can use Colima to start a container environment that includes Docker and Kubernetes. Run the following command:
colima start --kubernetesThis command starts a virtual machine that includes the Docker and Kubernetes runtime environments. By default, Colima allocates 2 CPUs, 2 GiB of memory, and 100 GiB of storage to the VM. If you need to adjust these parameters, you can set them using additional flags at startup. For example, to start a VM with 4 CPUs and 4 GiB of memory:
colima start --cpu 4 --memory 4You can also stop the VM with colima stop, or delete it with colima delete and then recreate a fresh instance.
4. Configuring and Using Docker BuildKit
Docker BuildKit is a modern build tool that provides faster builds and more features. Starting with Docker 23.0.0, BuildKit is enabled by default, which means you no longer need to enable it via environment variables such as DOCKER_BUILDKIT=1. However, if you need the advanced features provided by docker buildx, you may need to install the docker-buildx plugin manually.
1. Install Docker Buildx
docker-buildx is an official Docker extension plugin used to support advanced BuildKit features such as multi-platform builds and cache optimization. Install docker-buildx via Homebrew:
brew install docker-buildxAfter installation, you can immediately run the following command to verify that docker-buildx is working properly:
docker-buildx versionIf you see output similar to the following, it means docker-buildx has been installed successfully:
Extended build capabilities with BuildKit2. Configure Docker Buildx
Although docker-buildx is installed successfully, the docker buildx command is not available by default. This is because docker buildx is an extension command that needs to be added to Docker’s CLI plugin directory via a symbolic link. Run the following command to complete this step:
mkdir -p $HOME/.docker/cli-plugins
ln -sf /opt/homebrew/bin/docker-buildx $HOME/.docker/cli-plugins/docker-buildxAfter creating the symbolic link, you can use BuildKit features directly through the docker buildx command. Run the following command to verify:
docker buildx versionIf everything is working correctly, you will see the version information for docker buildx.
3. Use BuildKit
Now, you can use BuildKit’s advanced features directly in your Dockerfile, such as
RUN --mount=type=bind,target=/path/to/cache,source=./local/cache \
/path/to/cache/build.shV. Summary
With Colima and Docker Buildx, we can easily enable Docker and BuildKit on macOS without relying on Docker Desktop. Colima provides a lightweight container runtime environment that supports multiple runtimes and architectures, while Docker Buildx adds powerful capabilities to Docker builds. This combination not only saves system resources but also offers greater flexibility and scalability. If you’re looking for a lightweight container development environment, Colima and Docker Buildx are definitely worth trying.
Comments
No comments yet — be the first to write one.