Installing Docker and Minikube on Windows 10/11: A Complete Tutorial

Installing Docker and Minikube on Windows 10/11: A Complete Tutorial

In this article, I will demonstrate how to install Docker and Minikube on a Windows 10 or newer machine.

Introduction

In today's world of microservice architecture applications, there is a need to mimic the Kubernetes setup on your local machine. This helps in getting hands-on experience with Kubernetes concepts, aiding the development team in developing, testing, and deploying applications similar to the production environment, fixing code related to production bugs locally, and setting up intercommunication between applications.

This article emphasizes the steps of installing Minikube without using third-party software such as Docker Desktop or Rancher Desktop, which consume a lot of memory and can cause laptop crashes or restarts due to insufficient memory. It provides the minimal setup required to operate the application locally.

What is Docker?

Docker is a platform and tool for building, packaging, and running applications inside containers. Containers contain code and all its dependencies, which help applications run quickly and reliably on different computing environments.

It also simplifies the process of managing application processes in containers, making it easier to build, test, deploy, and scale applications across any environment.

What is Minikube?

Minikube is an open-source tool designed to run Kubernetes locally on your computer. It allows developers to develop and test applications in a Kubernetes environment on their computers, without the need for a complex cluster setup.

It runs a single-node cluster inside a VM on your computer, which is sufficient to explore, learn, and develop applications on Kubernetes locally.

Install Windows Subsystem for Linux (WSL2)

Following are the steps to install the Linux OS on a Windows machine. This creates the virtualization and helps us run Linux and Windows-based images on a Windows machine.

  1. Search for Windows features from the Windows search bar and open the Windows Features dialog. Turn Windows features on or off -> Select the checkboxes for Hyper-V and Windows Subsystem for Linux.

  2. Restart the computer.

Open the Terminal prompt and enter these commands -

wsl -l -v

wsl --set-default-version 2 // set wsl2 as a default version

wsl --install -d Ubuntu (this will take time to install Ubuntu on Windows)

wsl -l -v  // check version

Install Docker on WSL2 using the Ubuntu Terminal

I have followed the steps to install Docker, which are written below and referred to from the official documentation here.

Open the Ubuntu terminal and execute the commands below.

1. sudo apt-get update (provide password for ubuntu user)

2. sudo apt-get install ca-certificates curl gnupg lsb-release

3. sudo mkdir -p /etc/apt/keyrings

4. sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 

5. sudo chmod a+r /etc/apt/keyrings/docker.asc

6. echo\
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release &&echo"$VERSION_CODENAME") stable"|\
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
        OR
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

7. sudo apt-get update

Install latest version of Docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Start Docker engine

sudo service docker start

The above command gives the message (but nothing starts!):

Starting Docker: docker

Type docker ps -a and it gives error:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.45/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied

OR

Type sudo docker run hello-world and it gives error:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

The issue lies within ipconfig tables or the current non-root user does not belong to docker group. To fix this, execute below command

sudo update-alternatives --config iptables

Select option 1 with path /usr/sbin/iptables-legacy

If you are getting the permission denied for executing any of the commands mention above, it means the current user is not in the docker group as is a non-root user. Execute the commands to set it up:

1. Create the docker group if it does not exist
   $ sudo groupadd docker

2. Add your user to the docker group.
   $ sudo usermod -aG docker $USER

3. Log in to the new docker group (to avoid having to log out / log in again; but if not enough, try to reboot):
   $ newgrp docker

4. Check if docker can be run without root
   $ docker run hello-world

5. Restart docker
   $ sudo systemctl restart docker

6. Look like the upgrade have recreate the socket without enough permission for the 'docker' group. Execute
   $ sudo chmod 666 /var/run/docker.sock

7. Start docker service
   $ sudo service docker start
   $ docker ps –a 
   $ docker run hello-world

Install kubectl on WSL2

I have referred the official documentation (click here) to install the kubectl on wsl2. I have extracted the commands below:

1. Execute command on Ubuntu - 

   curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

2. Validate the binary

   curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

3. echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

   Response should be kubectl: OK

4. Install kubectl by providing admin user credentials if asked for sudo command

   sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

5. kubectl version --client or kubectl version --client --output=yaml

   Output shown below -

Install Minikube on WSL2

Please refer official documentation here.

To install the latest minikube stable release on Windows, x86-64 architecture using binary download, execute the below commands:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

Go ahead and create a cluster while we are here.

minikube start --vm-driver=docker
// it should spin up in about a minute or so

Wrap-up

In this way, we are now ready to explore Kubernetes using Minikube on your local machine. There are exciting configurations to increase the CPUs and memory according to your local machine's specifications and availability. By default, it creates the cluster with 2 CPUs and 6300MB of memory.

As a good practice, before shutting down your local machine, prune the Docker system and delete Minikube by executing these commands:

docker system prune

minikube delete

Happy coding and DevOps!