Replacing Docker Desktop with WSL2 and/or Rancher Desktop on Windows

When I have wanted to build a container image and/or run a little local Kubernetes on my laptop I traditionally have used Docker Desktop for both. With their recent announcement I went looking for possible alternatives.

This initial post focuses on Windows — I will do a follow-up one with a view to the Mac.

Docker Engine on Linux via WSL2

Note in the above announcement that it says “that licensing for Docker Engine and the upstream Docker and Moby open source projects is not changing.” Docker Engine for Linux is fully open sourced (under the Apache license) and we can continue to use that for free. What Docker Desktop gave us in addition to that on Windows was running a Linux VM they set up for us wrapped around it (these days also running via WSL2), installation of the local CLI for and to map through to that VM, as well as installing a containerised Kubernetes in that VM for us optionally as well.

Given my main laptop for container work at the moment is a Windows 10 machine where I heavily use Ubuntu via WSL2, I was curious if I could just install Docker in Ubuntu there and have it work within that Linux environment. The good news is yes you can!

First, install Ubuntu WSL2 if you have not already. MS documents that here. Then you can just follow the instructions here with one exception — https://docs.docker.com/engine/install/ubuntu/. The exception is that there is no systemd in WSL2 so you just have to run to start dockerd directly. You might want to run it with an at the end in to run it in the background if you don’t want to dedicate a tab in your Terminal to it in the foreground that you’ll need to close or ctrl-c out of when you’re done.

This works quite well in a couple respects:

  • It automatically maps the ports through so that you can do a and then go to http://localhost:8080 in your browser on the Windows side
  • Not only can you run your docker commands and scripts within WSL2 instead of via the Command Prompt or PowerShell but many IDEs like Visual Studio Code can sync your code to the WSL side and run things there natively. This is detailed for VS Code here — https://code.visualstudio.com/blogs/2019/09/03/wsl2

So, if all you wanted Docker Desktop for is doing and of Linux containers then you can just uninstall Docker Desktop and do the above instead — sticking to the opensource docker engine and saving you from having to pay Docker for Desktop.

For Windows Containers, though, it doesn’t appear possible to install just the Docker Engine outside of Docker Desktop on Windows 10 — https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-10#install-docker.

Rancher Desktop for Kubernetes

That sorts us out for straight commands for our Linux containers, but what about the local Kubernetes it provided? There are various ways you could do that also in Ubuntu under WSL (kind etc.) but I also recently stumbled on Rancher Desktop which is free and open source and seems to be a great new tool for this use-case. I decided to give it a try.

This tool:

  • Installs a new Linux VM in WSL2 that has a Kubernetes cluster based on k3s as well as installs various components in it such as KIM (for building docker images on the cluster) and the Traefik Ingress Controller
  • It installs the kubectl and Helm CLIs on the Windows side linked to them
  • A nice Windows app to manage its settings and help facilitate its upgrades

If you do a this is what it ships with out-of-the-box (using only 1.2GB of RAM total):

pod/coredns-7448499f4d-rtczv
pod/helm-install-traefik-crd-cptbv
pod/helm-install-traefik-jpz4b
pod/local-path-provisioner-5ff76fc89d-9rpn8
pod/metrics-server-86cbb8457f-hszhp
pod/svclb-traefik-cn88g
pod/builder-vk9gm
pod/traefik-97b44b794-q56mm
service/kubernetes
service/kube-dns
service/metrics-server
service/builder
service/traefik
daemonset.apps/svclb-traefik
daemonset.apps/builder
deployment.apps/coredns
deployment.apps/local-path-provisioner
deployment.apps/metrics-server
deployment.apps/traefik
replicaset.apps/coredns-7448499f4d
replicaset.apps/local-path-provisioner-5ff76fc89d
replicaset.apps/metrics-server-86cbb8457f
replicaset.apps/traefik-97b44b794
job.batch/helm-install-traefik-crd
job.batch/helm-install-traefik

Not bad considering it has metrics-server so works as well as an Ingress controller etc.

I tried a go-to simple example I use for Kubernetes (swapping out my usual Ingress class annotation for the traefik I see running):

apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 2
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.10
ports:
- containerPort: 8080
resources:
requests:
memory: "512Mi"
cpu: "0.5"
limits:
memory: "512Mi"
cpu: "0.5"
readinessProbe:
httpGet:
scheme: HTTP
path: /
port: 8080
livenessProbe:
httpGet:
scheme: HTTP
path: /
port: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 8080
selector:
app: hello-kubernetes
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-kubernetes
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: hello-kubernetes
port:
number: 80

I could see the pod running so I figured I wanted to see I could get to it via the Ingress controller. I did a and got this back:

NAME               CLASS    HOSTS   ADDRESS         PORTS   AGE
hello-kubernetes <none> * 172.19.152.78 80 79s

And sure enough I went to http://172.19.152.78 on my browser on the Windows side and it worked!

I also noticed another thing in the Rancher Desktop app — a port forwarding tab:

This is listing all the Services on the cluster. I clicked the Forward button next to hello-kubernetes and port 55350 appeared. I then went to http://localhost:55350 and it also worked!

So, now that we know that our local Kubernetes experience is good, let’s check out another thing we used to get out of Docker Desktop — I could build a container image locally with a and then immediately use it within the cluster. The way that you do that here is with kim. This mimics the command but it hands the build off to a service running on our local Kubernetes cluster to do the builds and pushes.

I got the Dockerfile for hello-kubernetes and built it with a instead of the usual . I then tried to update the definition above to use that local image instead (it hadn’t been pushed anywhere) and got an image pull error. It turns out that you need to change in the Pod Spec to or in order to use these local images on the Kubernetes VM that kim builds — which makes sense. But otherwise that works great as well!

Conclusion

With the seeming exception of Windows containers, I feel that the combination of docker engine via WSL2 for when you need and Rancher Desktop for when you need a local Kubernetes experience is a great free alternative to Docker Desktop on Windows.

Give it a try today!