DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Running Linux Containers on WSL using Nomad
Georg MΓΌller
Georg MΓΌller

Posted on

Running Linux Containers on WSL using Nomad

Hashicorp Nomad is a workload orchestration engine that allows you to deploy and operate workloads on multiple machines or VMs.

As such Nomad is a direct competitor to Kubernetes. In contrast to Kubernetes, Nomad allows to orchestrate not only containerized workloads, but also all kinds of non-containerized workloads like simple Linux processes, Java applications, Windows (IIS) applications, ... .

While it is flexible, it is also more simple than Kubernetes.

So recently I started looking into Nomad.

I set up Nomad on my Windows machine using chocolatey using

choco install nomad
Enter fullscreen mode Exit fullscreen mode

Starting Nomad using, to setup a development agent

nomad agent -dev
Enter fullscreen mode Exit fullscreen mode

While this successfully started Nomad, it did not start its Docker Task Driver, which allows to place Docker container in the Nomad Cluster. The error in the log was:

Docker is configured with Linux containers; switch to Windows containers

Searching for a solution I found this issue in the repo: Support Linux images in Docker for Windows

Basically the issue says, that the integration should work, but it is not being verified in tests. It also seems like some people got it to work while some are not.

I really don't see however, how someone could get this to run, as the fingerprinter of the docker container driver always throws an error: fingerprint.go

Some weeks later, I decided to take a different approach installing Nomad directly into the WSL Linux distribution. This allowed me to run Linux containers, while not having to launch an additional VM. These are the required steps.

Steps to get the Docker Task Driver working

  • Install Docker for Desktop
  • Start Docker for Desktop and make sure you have the Linux Kernel package installed; Docker will open a Microsoft website where you can find the download
  • Make sure you have the WSL2 backend enabled in Docker for Desktop - Settings Docker for Desktop - General - Use the WSL2 based engine
  • Download a Linux Distro from Microsoft Store, I have been using Ubuntu 20.04
  • Install Ubuntu
  • Make sure Ubuntu is the Default Linux Distro in WSL using
wsl -s Ubuntu-20.04
Enter fullscreen mode Exit fullscreen mode
  • Enable WSL integration for Ubuntu in the Docker for Desktop settings; you find it in Settings > Resources > WSL integration Docker for Desktop - Settings - Resources - WSL integration - Ubuntu 20.04 enabled
  • Install Nomad in Ubuntu (see Nomad docs)
  • Start it using
nomad agent -dev --bind=0.0.0.0
Enter fullscreen mode Exit fullscreen mode
  • This successfully started Nomad (1.1.3 at time of writing)
  • A look in the log confirmed the Docker Task Driver started
[DEBUG] client.driver_mgr: detected drivers: drivers="map[healthy:[raw_exec docker] undetected:[exec java qemu]]"
Enter fullscreen mode Exit fullscreen mode

If Docker is not detected at this point check your user is in the docker group using

groups
Enter fullscreen mode Exit fullscreen mode

If you cannot see the docker group, add it using

sudo usermod -aG docker $USER
Enter fullscreen mode Exit fullscreen mode

Then restart WSL by exiting the shell.

Test

Finally a quick test, its very easy to test if you can deploy a container to Nomad.

nomad init
Enter fullscreen mode Exit fullscreen mode

This creates a example.nomad file, that includes all configurations to deploy a Linux Redis container.

Running

nomad run example.nomad
Enter fullscreen mode Exit fullscreen mode

starts the deployment and successfully starts the container:

  βœ“ Deployment "d3935b56" successful

    2021-08-04T14:13:54+02:00
    ID          = d3935b56
    Job ID      = example
    Job Version = 0
    Status      = successful
    Description = Deployment completed successfully

    Deployed
    Task Group  Desired  Placed  Healthy  Unhealthy  Progress Deadline
    cache       1        1       1        0          2021-08-04T14:23:52+02:00
Enter fullscreen mode Exit fullscreen mode

Nice !!!!

Checklist

Make sure

  1. you have an update version of Nomad, I am using 1.1.3 at the time of writing,
  2. WSL2 mode is activated in Docker settings,
  3. the distro is activated for WSL integration in Docker settings,
  4. and (not WSL specific, but I always tend to forget it) add your user to the Docker group in WSL

Conclusion

After several failed attempts, using this checklist I managed to successfully start Nomad jobs on 2 different PCs.

Top comments (0)

What are you learning?

Each week we have a Welcome Thread where we'd love to hear about it.