Getting started with Docker and Kubernetes on Windows 10

This article was originally posted at LearnK8s on the 25th April, 2018 by myself.

15 min read

Getting started with Docker and Kubernetes on Windows can be daunting when you don't know where to begin.
And it doesn't help that installing the software isn't exactly a walk in the park.
In fact, you should already be a Docker and Kubernetes expert to navigate the options on how to install them.

But don't worry!

If you're just starting your journey with containers and Kubernetes on Windows this article is for you.
You'll learn how to make the right choices when it comes to setting up your development environment on Windows.

Let's start with Docker.

Using Windows 10 Home? You won't be able to run Docker for Windows

When the people at Docker decided to implement Docker on Windows, they opted for Hyper-V as their virtualisation technology. The benefit is crystal clear: excellent performance and a native hypervisor.
Unfortunately not all Windows versions ship with Hyper-V.
And if you're using Windows 10 Home or Student edition, you are out of luck. You won't be able to install and run Docker for Windows.

But it's not game over.

There are plenty of replacements based on Docker Machine such as Docker Toolbox or minikube.
The way Docker Machine works is simple: there's a virtual machine that runs Linux and Docker. And you connect from your host to the remote Docker daemon in that virtual machine.
Minikube is the somehow one of the most interesting virtual machine based on Docker Machine — that's if you're into running Kubernetes clusters.
In fact, minikube is a virtual machine that runs Docker and Kubernetes. It's usually used to run Kubernetes only, but you can use it to run Docker containers too.

You won't reach the same speed as Docker for Windows, but you can build and run containers without Hyper-V.

With Windows 10 Pro, Docker for Windows is the best — until it isn't

You have the latest Windows 10 Pro, and you can install Docker for Windows.
Excellent performance and excellent developer experience. You're sorted, aren't you?

Maybe.

The hypervisor used by Docker for Windows is extremely powerful — indeed it's called a Type-1 hypervisor.
It's so powerful that it doesn't play nicely with weaker hypervisors such as the one in VirtualBox — or Type-2 hypervisors.
You can't have Type-1 and Type-2 hypervisors running at the same time on your machine. Or in other words, if you run Docker for Windows, you won't be able to start your virtual machines on VirtualBox.
Depending on your setup, this may be an insignificant detail.

Perhaps you're fully committed to a containerised world, and you left virtual machines behind.
An old and distant memory.
But if you're still relying on virtual machines and tools such as Vagrant, perhaps you should be aware of the annoyance.

You can enable and disable the Hyper-V hypervisor at will, but it requires a restart of your computer.

If you're frequently switching from containers to virtual machines, perhaps minikube is a more convenient choice. You don't need to restart your computer when you change from containers to virtual machines.
But you don't benefit from the extra performance or the improved experience.
Lastly, if you're interested in running Windows containers — aka containers with a base image that inherits from Windows — Docker for Windows is the only option.
And you will need Windows 10 Pro or Enterprise for that.

Running a local Kubernetes cluster

If you want to run Kubernetes locally, you should consider minikube.

Minikube is a virtual machine running on an embedded Linux Distribution (Buildroot) and comes with the Docker daemon pre-installed.

Prerequisites

You can download and install all the dependencies such as Docker for Windows, Docker Toolbox, VirtualBox, kubectl, Docker CLI, etc. from the official websites, but it's hard work.
You have to visit the website, hope that the URL is still valid, search for the download page, select the right version, download it, install it and finally add it to your path. It's doable, but I'm sure you would rather spend time doing more coding than chasing and installing executables from the internet.

Enter Chocolatey.

Chocolatey is a package manager for Windows. You tell it what executables you wish to install, and Chocolatey installs them on your behalf.
You're outsourcing all the hard work of provisioning software to someone else.

1. Installing Docker and Kubernetes on Windows 10 Pro

Installing Docker

You should be aware that Docker requires VT-X/AMD-v virtual hardware extension to be enabled before you can run any container. Depending on your computer, you may need to reboot and enable it in your BIOS.

You can check if VT-X/AMD-v is enabled by running systeminfo from the
command prompt.

If you're unsure VT-X/AMD-v was enabled, don't worry. If you don't have it, Docker will greet you with the following error message:

Hardware assisted virtualization and data execution protection must be enabled in the BIOS.

Another common error has to do with the Hyper-V hypervisor not being enabled. If you experience this error:

Unable to start: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: 'MobyLinuxVM' failed to start.
Failed to start the virtual machine 'MobyLinuxVM' because one of the Hyper-V components is not running.

error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

The error above is suggesting that your Docker installation is not behaving normally and wasn't able to start.

You should start your Docker daemon before you connect to it.

Installing Minikube on Hyper-V

You can download minikube with:

choco install minikube -y

Before you start the cluster, you should create an external network switch. First, you need to identify what network adapters you have on your computer. You should ignore the virtual interface and focus on real, live, physical network adapters such as Ethernet or WiFi. Picking a real adapter will let you share the internet connection with the virtual switch.

To inspect your current network adapters, you can use the Get-NetAdapter cmdlet in Powershell. Click left lower corner Windows icon and start typing "PowerShell" to open it.

Please note that --vm-driver=hyperv --hyperv-virtual-switch=minikube is necessary only for the first start. If you wish to change the driver or the memory you have to minikube destroy and recreate the VM with the new settings.

If you wish to use VirtualBox or any other executable that uses a Type-2 hypervisor, you should disable it and restart your computer first.

Open a new command prompt as an administrator and type the following:

bcdedit /set hypervisorlaunchtype off

After restarting your device, you should be able to use VirtualBox as usual. If you wish to use Docker and minikube again, you should enable Hyper-V and restart your machine.

Open a new command prompt as an administrator and type the following:

bcdedit /set hypervisorlaunchtype auto

Restart, and now you're ready to run and deploy containers to Kubernetes!

2. Installing Docker and Kubernetes on Windows 10 Home

If you're planning on using Windows 10 Home or Student edition, you can probably save yourself from installing another Docker Machine tool such as Docker Toolbox. You should use minikube as a remote Docker daemon as well as your local Kubernetes cluster.

You can download and install minikube with:

choco install minikube -y

At the end of the installation, you can start minikube with:

minikube start

The command will download an ISO for VirtualBox and start the virtual machine. Once started, you should be able to query the Kubernetes cluster with:

kubectl get nodes

And see a single node.

To connect to the remote Docker daemon, you should install the Docker client with:

choco install docker -y

You can connect to the minikube remote Docker daemon with:

@FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i

Please note that you should type the above command every time you open a new terminal. A shorter way to remind yourself about that command is to type minikube docker-env.

If the connection was successful, you should be able to list all the running containers with:

docker ps

You should see a lot of running containers. Most of those belong to Kubernetes.

You've made it this far: you're ready.

But before you move on, you should be aware of some the limits of using minikube as your remote Docker daemon.

Docker was designed in two parts:

the Docker daemon — you can think about it as a server with an API. You can send commands to the API and Docker will receive and execute them on your behalf.

the Docker CLI — the executable that sends the commands to the Docker daemon API

Most of the time you're interacting with the Docker CLI, and you don't see the Docker daemon.

So why having a client and a server?

Why not having a single binary?

It all comes down to flexibility.

When you run Docker for Windows, you Docker CLI is connected to your local Docker daemon.

Perhaps you want to build containers on a remote machine. Perhaps you can't run Hyper-V on your machine, and your Docker daemon is installed in a virtual machine in VirtualBox. Precisely the case if you're running minikube. Your Docker CLI is connected remotely to a Docker daemon located inside the minikube virtual machine.

Latest articles

Laravel is an excellent framework for developing PHP applications. Whether you need to prototype a new idea, develop an MVP (Minimum Viable Product) or release a full-fledged enterprise system, Laravel facilitates all of the development tasks and workflows. How you deal with deploying the application is a different story. Vagrant is very good with setting up a local environment…

I’ve been applying TDD (Test Driven Development) religiously for the past 5 years and now cannot imagine where I would even start from, in any code if it’s not from a test. The advantages TDD brought along with it are numerous and in my case, vital, for working on projects of a certain calibre. Even though the complexity of any code is now irrelevant to me when it comes to TDD…

I honestly feel obliged to write this article because I feel that most developers think about Event Sourcing as only another PoEAA (Pattern of Enterprise Application Architecture). Maybe reserved to software models which have a certain level of complexity or at least they need to look like they do so that the time and cost is justified. Event Sourcing is a lot more than just an…

Laravel is an excellent framework for developing PHP applications. Whether you need to prototype a new idea, develop an MVP (Minimum Viable Product) or release a full-fledged enterprise system, Laravel facilitates all of the development tasks and workflows. How you deal with…

I’ve been applying TDD (Test Driven Development) religiously for the past 5 years and now cannot imagine where I would even start from, in any code if it’s not from a test. The advantages TDD brought along with it are numerous and in my case, vital, for working on projects of a…

I honestly feel obliged to write this article because I feel that most developers think about Event Sourcing as only another PoEAA (Pattern of Enterprise Application Architecture). Maybe reserved to software models which have a certain level of complexity or at least they need to…