[macOS] Use Homebrew (brew) to install Docker Desktop, Docker Compose and Kubernetes (K8S) on macOS

Docker Desktop, Docker Compose and Kubernetes (K8S) on macOS

Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to build and share containerized applications and microservices. Docker Desktop includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper.

Some of the key features of Docker Desktop include:

  • Ability to containerize and share any application on any cloud platform, in multiple languages and frameworks

  • Easy installation and setup of a complete Docker development environment

  • Includes the latest version of Kubernetes

  • Automatic updates to keep you up to date and secure

  • On Windows, the ability to toggle between Linux and Windows Server environments to build applications

  • Fast and reliable performance with native Windows Hyper-V virtualization

  • Ability to work natively on Linux through WSL 2 on Windows machines

  • Volume mounting for code and data, including file change notifications and easy access to running containers on the localhost network

  • In-container development and debugging with supported IDEs

Installation

Install Homebrew (brew).

1
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Insall Docker Desktop.

1
$ brew install --cask docker

Check Docker and Docker Compose version.

1
2
3
4
5
$ docker -v
Docker version 20.10.7, build f0df350

$ docker-compose -v
docker-compose version 1.29.2, build 5becea4c

Enable Kubernetes

Docker Desktop includes a standalone Kubernetes server and client, as well as Docker CLI integration that runs on your machine. The Kubernetes server runs locally within your Docker instance, is not configurable, and is a single-node cluster.

The Kubernetes server runs within a Docker container on your local system, and is only for local testing. Enabling Kubernetes allows you to deploy your workloads in parallel, on Kubernetes, Swarm, and as standalone containers. Enabling or disabling the Kubernetes server does not affect your other workloads.

To enable Kubernetes support and install a standalone instance of Kubernetes running as a Docker container, go to Preferences > Kubernetes and then click Enable Kubernetes.

https://docs.docker.com/desktop/images/kube-enable.png

Click Apply & Restart to save the settings and then click Install to confirm. This instantiates images required to run the Kubernetes server as containers, and installs the /usr/local/bin/kubectl command on your machine.

1
2
3
4
5
6
7
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:53:14Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}

$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
docker-desktop Ready control-plane,master 4h8m v1.21.2

FAQs

Kubernetes failed to start

Choose Troubleshoot from the menu bar to see the troubleshoot options.

https://docs.docker.com/docker-for-mac/images/menu/troubleshoot.png

The Troubleshoot page contains the following options:

  • Restart Docker Desktop: Select to restart Docker Desktop.

  • Support: Developers on Pro and Team plans can use this option to send a support request. Other users can use this option to diagnose any issues in Docker Desktop. For more information, see Diagnose and feedback and Support.

  • Reset Kubernetes cluster: Select this option to delete all stacks and Kubernetes resources. For more information, see Kubernetes.

  • Clean / Purge data: This option resets all Docker data without a reset to factory defaults. Selecting this option results in the loss of existing settings.

  • Reset to factory defaults: Choose this option to reset all options on Docker Desktop to their initial state, the same as when Docker Desktop was first installed.

  • Uninstall: Choose this option to remove Docker Desktop from your system.

Kubernetes starting

May be can’t download k8s images from k8s.gcr.io in the limited network environment. Please check you network to download these images from k8s.gcr.io, or from other mirrors.

Pull and tag multiple images.

Remember to replace coredns:1.8.0 and pause:3.4.1 with your prefer image and version.

1
2
3
4
5
6
7
8
9
10
$ REGISTRY_MIRROR=registry.aliyuncs.com/google_containers

$ IMAGE_VERSIONS="coredns:1.8.0 pause:3.4.1"

$ for IMAGE_VERSION in ${IMAGE_VERSIONS}; \
do \
docker pull ${REGISTRY_MIRROR}/${IMAGE_VERSION} && \
docker tag ${REGISTRY_MIRROR}/${IMAGE_VERSION} k8s.gcr.io/${IMAGE_VERSION} && \
docker rmi ${REGISTRY_MIRROR}/${IMAGE_VERSION}; \
done

References

[1] docker — Homebrew Formulae - https://formulae.brew.sh/cask/docker

[2] Install Docker Desktop on Mac | Docker Documentation - https://docs.docker.com/docker-for-mac/install/

[3] Docker Desktop for Mac and Windows | Docker - https://www.docker.com/products/docker-desktop

[4] Install Docker Compose | Docker Documentation - https://docs.docker.com/compose/install/

[5] Deploy on Kubernetes | Docker Documentation - https://docs.docker.com/desktop/kubernetes/

[6] Logs and troubleshooting | Docker Documentation - https://docs.docker.com/docker-for-mac/troubleshoot/

[7] AliyunContainerService/k8s-for-docker-desktop: 为Docker Desktop for Mac/Windows开启Kubernetes和Istio。 - https://github.com/AliyunContainerService/k8s-for-docker-desktop

[8] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/

[9] Kubernetes