Colima with Docker on M4 Mac

Colima is a container runtime for macOS that provides a lightweight and efficient alternative to Docker Desktop. It leverages Lima, a Linux virtual machine manager, to run containers on macOS, making it particularly useful for users with Apple Silicon (M1/M2/M3/M4) chips.

What is Colima?

Colima stands for “Containers on Lima.” It is designed to be a drop-in replacement for Docker Desktop, providing a similar user experience but with better performance and compatibility on macOS, especially on Apple Silicon. Colima supports Docker and Kubernetes, making it a versatile tool for containerized development.

How to Use Colima

Installation

  1. Install Colima: You can install Colima using Homebrew, a popular package manager for macOS.
brew install colima
  1. Install Docker CLI: If you don’t already have the Docker CLI installed, you can install it using Homebrew as well.
brew install docker
brew install docker-compose
  1. Configure docker-compose as a Docker plugin so you can use docker compose as a command instead of the legacy docker-compose script.

First, create a folder in your home directory to hold Docker CLI plugins:

mkdir -p ~/.docker/cli-plugins

Then symlink the docker-compose command into that new folder:

ln -sfn $(brew --prefix)/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose

Run docker compose version to verify that the plugin is installed correctly.

% docker compose version
Docker Compose version 2.32.2

Starting Colima

  1. Start Colima: To start Colima, simply run the following command:
colima start

This command will start a Linux virtual machine and configure it to run Docker containers.

  1. Check status: To verify that Colima is running, you can use the status command.
% colima status
INFO[0000] colima is running using macOS Virtualization.Framework
INFO[0000] arch: aarch64
INFO[0000] runtime: docker
INFO[0000] mountType: sshfs
INFO[0000] socket: unix:///Users/romeo/.colima/default/docker.sock
  1. Verify Installation: You can verify that Colima is running by checking the Docker version.
docker version

You should see output indicating that Docker is running and connected to the Colima backend.

Configure Shell Environment

To configure your shell environment to use Colima, you can add the following lines to your shell profile (e.g., ~/.zshrc or ~/.bashrc):

export COLIMA_VM="default"
export COLIMA_VM_SOCKET="${HOME}/.colima/${COLIMA_VM}/docker.sock"
export DOCKER_HOST="unix://${COLIMA_VM_SOCKET}"

Then, reload your shell configuration:

source ~/.zshrc

Using Colima

  1. Run Containers: You can use Docker commands as you normally would to run containers. For example, to run a simple Nginx container, use:
docker run -d -p 8080:80 nginx
  1. Manage Containers: You can manage your containers using standard Docker commands like docker ps, docker stop, and docker rm.

  2. Stop Colima: When you’re done, you can stop Colima with:

colima stop

% docker compose version Docker Compose version 2.32.2

Benefits of Using Colima

  • Performance: Colima provides better performance on macOS, especially on Apple Silicon chips, compared to Docker Desktop.
  • Compatibility: It supports both Docker and Kubernetes, making it a versatile tool for containerized development.
  • Lightweight: Colima is lightweight and consumes fewer resources compared to Docker Desktop.

By using Colima, you can efficiently run and manage containers on your macOS system, leveraging the power of Apple Silicon for improved performance.