Introductionalmost two years ago, Docker announced the capability of switching between the Linux and Windows containers "mode" (far from the right click that we have today).
At that time, I wrote a blog post on how to run both daemons at the same time (http://darthnunix.blogspot.ch/2016/10/docker-for-windows-2-daemons-enter-in.html)
Fast forward to 2018, and while we were blogging on how to get the TLS connection from WSL docker client with Rory McCune (https://raesene.github.io/blog/2018/03/29/WSL-And-Docker/), another blog post, by Stefan Stranger drew my attention (read: blew my mind) as I was trying to reproduce the same: how could I "bind" the docker socket in WSL with the Docker for Windows Linux mode socket (https://blogs.technet.microsoft.com/stefan_stranger/2018/04/02/access-my-docker-for-windows-kubernetes-cluster-from-debian-wsl/)
From 1 to 2 daemon: DemonHunter mode achievedNow that we have all the required setup resources, let's bind them together. And because there's nothing as "you just have to ...", I might point out at obvious steps, so just skip them if you already know or have implemented them.
- You have Windows 10 installed
- You have WSL enabled (https://docs.microsoft.com/en-us/windows/wsl/install-win10)
- You have Docker for Windows, Edge channel installed (https://docs.docker.com/docker-for-windows/install/)
- Install the Docker client in WSL as described in the "Third up" step from Rory's blog
- Build the Npiperelay according to Craig Wilhite's blog
- The only change is in the "Last steps" and the content of the script. Change the line:
exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine",nofork
exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine_windows",nofork
$ ./docker-relay &
$ docker version
Here is the gif showing both daemons running in parallel:
Cool, but WHY?!?Well, as an hobbyist, I will always answer: why not?
Then, the "more technical" reason would be that now I'm able to run in parallel both Windows Containers and Linux Containers On Windows (LCOW) and Linux Containers on MobyLinuxVM which brings now the more than famous Kubernetes (k8s) as a single node cluster.
Now, as I'm really not a Dev, I would be more than interested to see how you could leverage this setup.
So tag me on Twitter so I can see how much fun you have.
Bonusfirst of all, if you reached this lines then I do thank you, and as such here is two small additions to the setup above if you want to make it "permanent":
- Create a Scheduled task
- First in WSL, make a link of your "docker-relay" file to the default system directory (in my case Corsair distro based on Ubuntu):
$ sudo ln -s ~/docker-relay /usr/local/bin/docker-relay
- Press the Windows key and type "Schedule"
- Click on the "Task Scheduler" option
- Click on the "Task Scheduler Library"
- On the right menu, click on Create Basic Task
- Give it a title > Click Next
- Select when the task should run > Click Next
- Select the "Start a Program option" > Click Next
- Pick your distro name (if custom) or simply "bash.exe" with the argument "-c sudo docker-relay" > Click Next
- Review the settings and check "Open the Properties dialog..." > Click Finish
- In order to have a "quiet mode" of the WSL window (not appearing on screen), select the option "Run wheter user is logged on or not" > Click OK
- Type your password
- Back to the Task Scheduler main window, scroll down to find your newly created task in the middle top section and click "Run" on the down right menu
- Restart or Log off/Login and your task should run
>>> Nunix Out <<<