After the updates to Docker Desktop's license agreement, other solutions for running Docker on your local machine have been brought to attention. These include Vagrant VM (https://blog.avenuecode.com/running-docker-in-a-vagrant-vm), WSL2 (https://blog.avenuecode.com/running-docker-engine-on-wsl-2), and Minikube (https://blog.avenuecode.com/running-docker-in-a-minikube-cluster), among others.
However, it's time to focus on Colima for several reasons. First, it's an open-source solution, making it adaptable to changes. Second, it offers container runtimes on macOS and Linux with minimal setup. Finally, it boasts features such as support for Intel and M1 Mac chips, port forwarding, Docker, Containerd, and Kubernetes.
This article will guide you through the installation and use of Docker and Kubernetes.
Installation
For all the steps, we're using a Mac with an Intel chip. The installation can be done through other resources, but we'll present it using Homebrew.
Installing Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
With Homebrew installed, we can now install Colima:
brew install colima |
Running Docker
To run Docker with Colima, you first need to download the free Docker CLI. This can be accomplished by executing the following command:
brew install docker |
Then, we can start Colima. When running Docker, we can simply use the following command.
colima start |
By running the following command, we can view the details of the Virtual Machine (VM) that is running Docker.
colima status |
colima start --cpu 1 --memory 2 --disk 10 |
If multiple VMs are running, they can be listed using the following command:
colima list |
In addition, Colima has other flags that can be utilized during startup.
You should now be prepared to use the Docker CLI on the host:
docker run hello-world |
To stop the process, simply use:
colima stop |
Running Kubernetes
Running Kubernetes is as straightforward as running Docker. First, we need to install Kubernetes.
brew install kubectl |
Then, we can start Colima with the following flag:
colima start --kubernetes |
Now we can test to see if everything has been successfully set up.
kubectl cluster-info |
To stop, we can use the identical command:
colima stop |
Connecting VSCode to Docker
To use VSCode in connection with your container, follow these straightforward steps. Begin by installing the Docker extension from the extension list.
After installation, use the shortcut Cmd+Shift+P and select Dev Containers:
Afterward, you should be able to view all the containers currently running.
A new window will open, attaching VSCode to your container.
References
https://github.com/abiosoft/colima
https://blog.avenuecode.com/running-docker-in-a-minikube-cluster
Author
João Fekete
João Fekete is a backend developer with a broad skillset and a passion for learning. He actively seeks opportunities to connect diverse areas of knowledge to solve problems.