Replace Docker Desktop with Minikube and Hyperkit on macOS
Bye bye Docker Desktop
Background
I have been using Docker Desktop
for while in macOS. The recent update of Docker Desktop was killing huge memory and storage in my machine. So I thought to give up on Docker Desktop and install Docker with Minikube
and Hyperkit
hypervisor. Minikube is used to run a Kubernetes cluster on local environment. But it also runs a Docker daemon that can be used to run containers. Hyperkit is an open-source hypervisor for macOS hypervisor, optimized for lightweight virtual machines and container deployment.
Docker Desktop
The docker engine which is the core software behind the docker only runs on Linux kernal(the engine can run on a physical or a virtual machine, but it can only run on top of a Linux kernel i.e. any OS that is flavour of Linux). Since Docker Engine only runs on Linux, developers who use Windows and macOS for software development cannot run the engine until they spin up a virtual machine (VM) that runs linux. That is where Docker Desktop comes in. Docker Desktop is a closed-source software that allows developers working on Windows/macOS to use container technology seamlessly on their development environment without needing to manage the complexity of operating a VM and all the dependencies that comes along with it (networking, virtualization, knowledge of linux etc).
Minikube Replacement
Docker Desktop is not the core technology that runs containers, it only aims to make it easier to develop software on Windows/macOS that runs in containers. So we can replace Docker Desktop with using native Linux VM(and Hypervisor). In here, I’m gonna use Minikube which designed to be used as a virtual machine(VM) as a replacement for Docker Desktop. Minikube required a hypervisor to run, so I’m using Hyperkit hypervisor. Following are the steps to follow.
1. Uninstall Docker Desktop
Following is the way to fully uninstall Docker Desktop and remove all it’s dependencies on local file system.
2. Install Minikube
Following are the required packages that needs to be installed with Minikube. I’m installing these packages with homebrew
.
3. Start Minikube
Following is the way to start Minikube. it starts a Kubernetes cluster with Docker daemon. When starting you may get an error. If error occurs try to clean Minikube and restart it as mentioned below.
4. Configure Minikube
Then we need to configure docker-cli
to use Minikube VM. Add following entry to ~/.bashrc
or ~/.zshrc
and then configure the Minikube VMs’ IP address.
5. Docker Volume Mapping
The docker volumes of the container will be created inside Minikube VM. It cannot directly access by the host macOS. We need to ssh
into Minikube VM to access them.
To access these docker volumes inside the Minikume VM from host machine, we need to mount the volume folder inside the Minikube into host(macOS) machine. Following is the way to do that.
This will mount the /private/var/services
directory inside the Minikube VM to /private/var/services
directory in the host machine. Now if you run the container, the volume mappings will be exists in the host machine.
6. Configure Memory and CPU
By default Minikube allocates 2 CPUs
and 2 GB memory
. We can increase Minikube cpu and memory in following ways.
7. Configure Insecure Docker Registry
Minikube allows users to configure the docker engine’s --insecure-registry
flag. We need to delete existing Minikube cluster before start the new cluster with --insecure-registry
flag.
8. Configure Docker Bridge
When the Docker service is started, a linux bridge is created on the host machine. The interfaces on the containers talk to the bridge, and the bridge proxies to the external world. Multiple containers on the same host can talk to each other through this bridge. The default docker bridge(docker0
) assigned a IP address 172.17.0.1
. We can dynamically configure the docker’s default bridge(docker0
) IP by using docker-opts=bip=<new ip/net mask>
flag. It specifies the IP address and netmask to use for docker’s default bridge(docker0
). Then the new docker containers will use IP addresses within this range.
9. Expose Docker REST API
Docker daemon which resides in the Minikube listens to the /var/run/docker.sock
which is a Unix socket
(Unix Sockets
use the local filesystem for communication, while IP Sockets
use the network). We can bind this Unix socket to TCP socket and expose outside. In following example I’m binding the Unix socket to TCP port 2375
on Minikube host via socat
. Then we can connect to this port from the host machine. This set up can be used to expose docker REST API(e.g via unencrypted channel) to outside. Then the REST clients can connects to the port 2375
to access the docker REST API.
10. Minikube without Kubernetes
The Minikube recent update(v1.24.0) supports to start Minikube VM without starting any Kubernetes in it. This is nice features if you want to run only Docker without Kubernetes. It will save more CPU of the computer as well. In my scenario I have run Minikube only with Docker(without Kubernetes) and run the Kubernetes cluster with K3d.
Reference
- https://dhwaneetbhatt.com/blog/run-docker-without-docker-desktop-on-macos
- https://itnext.io/goodbye-docker-desktop-hello-minikube-3649f2a1c469
- https://dev.to/coherentlogic/learn-how-to-mount-a-local-drive-in-a-pod-in-minikube-2020-3j48
- https://dev.to/coherentlogic/learn-how-to-mount-a-local-drive-in-a-pod-in-minikube-2020-3j48
- https://blog.arkey.fr/2018/06/18/minikube-with-hyperkit/
- https://www.shellhacks.com/minikube-start-with-more-memory-cpus/
- https://harikrishnakanchi.github.io/blog/devlog-a-story-of-kubernetes-docker-and-subnets.html