Running Linux Containers on WSL using Nomad
Tags: nomad, container, windows, wsl
Published: 2021-08-28 16:15:09

---
title: Running Linux Containers on WSL using Nomad
published: true
description: This article describes the necessary steps, getting Nomad, a worload orchestrator, to run Linux containers on Windows WSL
tags: nomad,container,windows,wsl
cover_image: https://images.unsplash.com/photo-1515444744559-7be63e1600de?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1600&h=420&q=80

---

[Hashicorp Nomad](https://nomadproject.io) 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
```

Starting Nomad using, to setup a development agent 

```
nomad agent -dev
```

While this successfully started Nomad, it did not start its [Docker Task Driver](https://www.nomadproject.io/docs/drivers/docker), 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](https://github.com/hashicorp/nomad/issues/2633) 

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](https://github.com/hashicorp/nomad/blob/42666b80143709cc6dd4ec7270706a06978e2a78/drivers/docker/fingerprint.go#L175)

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](https://i.imgur.com/AocXzAd.png)
* 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
```
* 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](https://i.imgur.com/rH8taiN.png)
* Install Nomad in Ubuntu (see [Nomad docs](https://www.nomadproject.io/docs/install))
* Start it using

```
nomad agent -dev --bind=0.0.0.0
```
* 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]]"
```

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

```
groups
``` 

If you cannot see the docker group, add it using 

```
sudo usermod -aG docker $USER
```

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
``` 

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

Running

```
nomad run example.nomad
```

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
```

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.