Run Docker with Colima in Macbook M1
Foto de Kyle Petzer en Unsplash
Since Docker Desktop is no longer free for commercial use, developers need alternatives to run containers on macOS. Colima is an excellent open-source solution that allows you to run containers on macOS (and Linux) without the licensing restrictions.
In this guide, I’ll show you how to set up and use Colima as a Docker Desktop alternative on your MacBook M1.
Prerequisites
Before we begin, make sure you have:
- macOS (preferably with Apple Silicon M1/M2)
- Homebrew installed
- Basic knowledge of Docker concepts
Installation and Setup
Step 1: Install Colima
The installation process is straightforward using Homebrew:
brew install colima
Step 2: Start the Colima VM
Launch the Colima virtual machine with your desired specifications. Here’s a recommended configuration for development work:
colima start --cpu 4 --memory 8 --disk 60 docker
Configuration breakdown:
--cpu 4
: Allocates 4 CPU cores--memory 8
: Allocates 8GB of RAM--disk 60
: Allocates 60GB of disk spacedocker
: Names the instance “docker”
You can adjust these values based on your system resources and needs.
Step 3: Configure Docker Integration
You have two options to make Docker commands work with Colima:
Option A: Set DOCKER_HOST Environment Variable
- Create or edit your
.zshenv
file:
touch ~/.zshenv
- Add the following line to the file:
export DOCKER_HOST=unix://$HOME/.colima/docker/docker.sock
- Reload your shell configuration:
source ~/.zshenv
Option B: Create a Symlink (Recommended)
This approach is more convenient as it doesn’t require environment variable changes:
sudo ln -sfn /Users/$USER/.colima/docker/docker.sock /var/run/docker.sock
This creates a symbolic link that makes Colima’s Docker socket available at the default Docker socket location.
Verification
To verify that everything is working correctly, run:
docker version
docker ps
You should see that Docker is now connected to the Colima backend.
Management Commands
Stop the VM
To stop the Colima virtual machine:
colima stop
List Profiles
To see all available Colima profiles:
colima ls
Delete a Profile
To remove a specific Colima profile:
colima delete <profile_name>
Check Docker Context
To see your current Docker context and available contexts:
docker context ls
Performance Tips
- Resource Allocation: Adjust CPU and memory based on your workload. For heavy development, consider increasing memory to 12-16GB.
- Disk Space: Monitor your disk usage, especially if you work with large images.
- Multiple Instances: You can run multiple Colima instances with different configurations for different projects.
Troubleshooting
If you encounter issues:
- Docker commands not working: Ensure the symlink is correctly created or DOCKER_HOST is properly set
- Performance issues: Try increasing CPU/memory allocation
- Permission errors: Check that the Docker socket has proper permissions
Conclusion
Colima provides a robust, free alternative to Docker Desktop for macOS users. It’s particularly well-suited for Apple Silicon Macs and offers excellent performance for containerized development workflows.
The setup process is straightforward, and once configured, you can use Docker commands exactly as you would with Docker Desktop. The main advantage is that you’re not limited by licensing restrictions and have full control over your container runtime environment.
Are you using Colima or another Docker Desktop alternative? Share your experience in the comments below!
Comments