Skip to main content

Docker + WSL: Get 2 daemon for the price of 1

Introduction

almost 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 achieved

Now 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.

Requirements:

  1. You have Windows 10 installed
  2. You have WSL enabled (https://docs.microsoft.com/en-us/windows/wsl/install-win10)
  3. You have Docker for Windows, Edge channel installed (https://docs.docker.com/docker-for-windows/install/)

Installation:

  1. Install the Docker client in WSL as described in the "Third up" step from Rory's blog
  2. 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
      to
      exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine_windows",nofork
  3. Run the script
    $ ./docker-relay &
  4. Try it out
    $ 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.

Bonus

first 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":
  1. 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 <<<

Comments

  1. nice post! Thanks for delivering a good stuff related to DevOps, Explination is good, nice Article
    anyone want to learn advance devops tools or devops online training
    DevOps Online Training
    DevOps Online Training hyderabad

    ReplyDelete
  2. I have Microsoft Office 2016 installed on a computer that I am replacing and I cannot find the DVD/Product Key. Is there any way to get MS Office 2016 With Crack

    ReplyDelete

Post a Comment

Popular posts from this blog

WSL: One Home to host them all

Introduction This blog post will explain how a single home mount can be shared accross all  the WSL instances. It was quite fun to find the idea and then make it happen. It will use all the tools currently available from WSL, so please don't expect a "Linux only" as Interopability will be heavily used. And before I start, here is my point of view about WSL: It's not only  Linux! It's different, just like GNU is different from Unix (yes I said it). We have finally the strength of both worlds combined. And while I do understand the "dev" aspect is meant to be reproducible in a Linux prod environment, the "ops" side is meant to take advantages of everything that can make the full environment feeling Home. Setup requirements In order to really enjoy this solution, I do recommend having 2 or more WSL distros installed or, if you fell like a real WSLCorsair, try @bketelsen crazy setup (I love it)! While the distros are downlo...

VSCode + WSL: the SSH way

The initial idea early 2017, Rich Turner made a demo where Visual Studio was used to develop C++ code, however the debugging environment targeted was WSL! With some magic, he showed something that he had forbidden from the initial release of WSL: writting directly to the WSL filesystem (still a big no-no actually). Of course, this triggered a lot of curiosity and the WSL Corsair had to loot from it too! SSH to save the day the biggest challenge was to find a way that not only could be easy to setup on both ends, and also would be approved  by the WSL team.  TLDR: if you use the Windows Path, You Die! #ThereBeDragons Another way, more Linux-oriented, needed to be used and hopefully a solution already existed and was simply waiting on being used: SSH🔐 The setup the setup is done in 2 distinct parts: Setup the SSH server on WSL Setup the SSH client on VSCode  While the SSH server is a standard procedure in Linux, finding the right  plugin for VSCode w...