View details here: https://gist.github.com/xynova/87beae35688476efb2ee290d3926f5bb
References:
- https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
- https://docs.docker.com/docker-for-windows
-
Open Docker settings dialog.
-
Under general, tick the
Expose daemon on tcp://localhost2375
option so that we can connect to Docker Daemon from the WSL Ubuntu VM. You can later explore options on how to secure the connection even further if you so desire: https://hub.docker.com/r/stefanscherer/dockertls-windows/. -
Make sure you share your C drive so that you can run containers with volumes
-
Definitely give Docker Daemon more memory. Maybe 6GB or more?
-
Enable Kubernetes (if you are not planning to use Minikube). Just tick the
Enable Kubernetes
option.
IMPORTANT: Make sure you select the docker-for-desktop
context through the Docker Desktop for Windows menu so that the .kube/config
file appropriately configured.
Back in your WSL ubuntu session configure the cli to talk to the Docker Daemon:
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc
Make sure connectivity to the Docker daemon work:
docker run --rm -ti hello-world
Configure Ubuntu to mount windows drives at /c or /e instead of /mnt/c or /mnt/e. The options = "metadata" line is not necessary but it will fix folder and file permissions on WSL mounts so everything isn’t 777 all the time within the WSL mounts:
cat << EOF | sudo tee /etc/wsl.conf
[automount]
root = /
options = "metadata"
EOF
NOTE: The previous action might take some time to propagate so a full Windows log-off or restart is required.
Once back, enter an ubuntu session:
ubuntu
# ubuntu@windows10:~$
Validate drives were mounted at the root:
ls "/c/Program Files"
Now lets run a sample container to make sure volumes are working
curl https://www.w3.org/Test/test > /c/index.html
docker run -ti --rm -p 2015:2015 -v /c/index.html:/srv/index.html abiosoft/caddy
You can now now browse to http://localhost:2015/ and should see a Test Dataset page.
Find your user directory on windows
ls /c/users
Create a soft link to the .kube/config
. Make sure you replace <YOUR_USER>
with your username on windows:
mkdir -p ~/.kube
ln -sf /c/users/<YOUR_USER>/.kube/config ~/.kube/config
Now you should be able to connect to Kubernetes on Docker for Windows
kubectl cluster-info
# Kubernetes master is running at https://localhost:6445
# KubeDNS is running at https://localhost:6445/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
#
# To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Test kubectx
kubectx
# docker-for-desktop
Test kubens
kubens kube-system
# Context "docker-for-desktop" modified.
# Active namespace is "kube-system".
kubectl get pods
# NAME READY STATUS RESTARTS AGE
# etcd-docker-for-desktop 1/1 Running 1 2h
# kube-apiserver-docker-for-desktop 1/1 Running 1 2h
# kube-controller-manager-docker-for-desktop 1/1 Running 1 2h
# kube-dns-86f4d74b45-z7n5h 3/3 Running 3 2h
# kube-proxy-6568r 1/1 Running 1 2h
# kube-scheduler-docker-for-desktop 1/1 Running 1 2h