Replacing Docker Desktop with minikube on Mac
On 2021-08-31 Docker announced that Docker Desktop would no longer be free for larger organizations. So we need a convenient replacement for Docker Desktop with minimal disruption — such as minikube, Hyperkit, or podman.
Copyright notice: This is an original article by xwi88, licensed under CC BY-NC 4.0. Commercial use is prohibited; please cite the source when reposting. Follow at https://github.com/xwi88
Terminology
- Docker Inc a US-based company that built open-source and closed-source software making it easier to develop, test, and run applications in containers.
- Docker Engine the core technology behind Docker. Open-source software that runs as a daemon on Linux and makes running containers on the Linux kernel possible. It owns the container lifecycle and the isolation of physical resources (compute, memory, storage) a container can access. It can run on physical or virtual machines, but only on a Linux kernel — i.e. on any Linux-flavored OS. This is important: the Docker engine runs only on Linux.
- Docker CLI CLI that developers usually use to interact with the docker engine. Includes the
dockeranddocker-composecommands. Again, open source. - Docker Desktop since Docker Engine runs only on Linux, developers on Windows and macOS can only run the engine after starting a Linux VM. That’s where Docker Desktop comes in. Docker Desktop is proprietary software that lets Windows/macOS developers use containers seamlessly in dev without managing VMs and all the details that entails (networking, virtualization, Linux knowledge, …). Docker Desktop is designed for use during software development; it has no place in production-like containers, where only
Docker Engineis involved.
Docker Engine inside a Linux VM.Requirements
- At least 2 CPUs
- At least 2 GB of free memory
- At least 20 GB of free disk space
- A network connection
- A container or VM manager, e.g. Docker, Hyperkit, Hyper-V, KVM, Parallels, podman, VirtualBox, or VMware Fusion/Workstation
Installation
If you’re sure you won’t run images in
docker desktopanymore, remove alldocker/docker desktoprelated config.
Homebrew install recommended
| |
If installing minikube via brew fails, try a manual install
| |
Verify the install
Run which minikube
After a brew install, if which minikube fails, run:
| |
remove the old minikube links and link the newly installed binary
Drivers
minikubeneeds aLinux VMto start onmac/windows; that’s the driver we configure. With--driver=dockeryou need the matchingDocker Desktopinstalled to reuse itslinux vm. Otherwise pick another driver. Supported drivers:
Linux
- Docker - container-based (preferred)
- KVM2 - VM-based (preferred)
- VirtualBox - VM
- None - bare-metal
- Podman - container (experimental)
- SSH - remote ssh
macOS
- Docker - VM + Container (preferred)
- Hyperkit - VM
- VirtualBox - VM
- Parallels - VM
- VMware Fusion - VM
- SSH - remote ssh
Windows
- Hyper-V - VM (preferred)
- Docker - VM + Container (preferred)
- VirtualBox - VM
- VMware Workstation - VM
- SSH - remote ssh
If you set --driver=docker, distinguish standard vs rootless docker
Standard Docker
| |
Rootless Docker
| |
The
--container-runtimeflag must be set tocontainerdorcri-o.
More driver config & usage: minikube drivers
Config commands
minikube config SUBCOMMAND [flags] [options]
minikube config helpminikube config defaults PROPERTY_NAME [flags]list displays all valid default settings for PROPERTY_NAMEminikube config view [flags]Display values currently set in the minikube config file.minikube config set PROPERTY_NAME PROPERTY_VALUE [flags]Sets an individual value in a minikube config fileminikube config get PROPERTY_NAME [flags]Returns the value of PROPERTY_NAME from the minikube config fileminikube config unset PROPERTY_NAME [flags]unsets PROPERTY_NAME from the minikube config file.
minikube config --help
| |
| |
Quick start
| |
Advanced start
Start command
- After some config changes you need
minikube deletethen restart
minikube start --driver=hyperkit or minikube start --driver=docker or another driver
A config like the following is recommended so you don’t have to enter the minikube vm to change things later. Key options:
--insecure-registry--registry-mirror--mountmount a host directory into theminikube vm- On MacOS,
/Users:/minikube-host/is mounted by default - Keep the mount path identical to avoid path-dependent programs failing to start
- Use
--mount-stringto mount on demand
- On MacOS,
--mount-stringspecify the mount directory--no-kubernetes--cpus--memory--image-mirror-country
minikube start --no-kubernetes --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com --mount /var/lib/minikube:/var/lib/docker
To use the minikube dashboard, start like this:
minikube start --cpus=2 --memory=2000mb \ --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
Tell Docker CLI to talk to minikube’s VM: eval $(minikube docker-env)
eval $(minikube docker-env) can be added to your shell rc (~/.zshrc or ~/.bashrc) so you don’t type it each time.
Possible issues
If you start minikube on top of Docker Desktop, it reuses that VM and config. Due to resource limits, minikube may fail to start.
| |
minikube deleteafter adjusting docker resources, delete and recreate, then restart
| |
Post-start environment check
Start command:
minikube start --no-kubernetes --insecure-registry=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
| |
eval $(minikube docker-env)lets the Docker CLI talk to minikube’s VM
.bash_profile or .zshrc or … if you want to use minikube’s daemon by default (or if you do not want to set this every time you open a new terminal).
docker infoto see the docker info in this terminal
| |
Open a new terminal and check
docker infoon the host (a machine that still has docker desktop installed — for comparison):
| |
Change image registries
Don’t make this change inside the minikube environment. Pass it at start:
minikube start --image-mirror-country='cn'etc.; see minikube start or Advanced start
minikube sshconnect to the minikube node
sudo mkdir -p /etc/dockercreate the docker directory
vi /etc/docker/daemon.jsonedit the config
daemon.jsondaemon.json config
| |
sudo systemctl daemon-reload
sudo systemctl restart docker
Dashboard
minikube dashboard
minikube start --driver=hyperkit --cpus=2 --memory=2000mb --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
minikube dashboard
Directory mounting
This will start the mount daemon and automatically mount files into minikube.
minikube mount <local directory>:<host directory>
Mapping/mount chain: host volumes<->docker desktop VM volumes<->docker container volumes
Driver default mount paths
Some hypervisors, have built-in host folder sharing. Driver mounts are reliable with good performance, but the paths are not predictable across operating systems or hypervisors:
| Driver | OS | HostFolder | VM |
|---|---|---|---|
| VirtualBox | Linux | /home | /hosthome |
| VirtualBox | macOS | /Users | /Users |
| VirtualBox | Windows | C://Users | /c/Users |
| VMware Fusion | macOS | /Users | /mnt/hgfs/Users |
| KVM | Linux | Unsupported | |
| HyperKit | Linux | Unsupported (see NFS mounts) |
These mounts can be disabled by passing –disable-driver-mounts to minikube start.
Running local apps
If you use directory mapping you must enable mounting, and mind the mount path — otherwise files or configs won’t be found.
Files or configs not found
Cause:
- With
docker desktop, the mapping is done for you:host volumes<->docker desktop VM volumes<->docker container volumes - When you run
docker runordocker-compose uplocally viaminikube, it actually runs inside theminikube vm, but theminikube vmhas no mapping of your host source code
Solution
Map/mount your working directory on the host:
minikube mount $HOME/workspace:$HOME/workspace- Mind the mapping path inside the minikube vm: the mount path must match the real path
- Watch directory permissions — mounting under your own user dir usually has no permission issues
- You can mount multiple directories
Put your source under one unified working directory for easy mounting and search, e.g.:
$HOME/workspacesource workspace; can be mounted as a whole$HOME/workspace/git.company.comcompany source workspace; company code only$HOME/workspace/github.comgithub source workspace$HOME/workspace/gitee.com
Start on boot
--mount --mount-string=$HOME/workspace:$HOME/workspacemay have issues; mounting viaminikube mountafter start is recommended
Mount only the current project directory
- Pro: fewer mount dirs, less space
- Con: switching projects means re-mounting — tedious
Prefer mounting the whole working directory (mind the size) — no extra steps when switching projects
| |
Mount the whole working directory
| |
Mount the whole working directory and run in the background
| |
Caveats
- After minikube starts, run
eval $(minikube docker-env) - Mount directories after minikube starts — see Running local apps
- Pass
--driverat start; if it’sdocker, make sure thedocker daemonis running - If the mount flag is wrong, run
minikube mount --killand remove the dir from theminikube vm minikube delete — you don't need to run it every time
More
- Using minikube as Docker Desktop Replacement
- How to interact with registries
- minikube-image-build
- containerd