Skip to content
Daniel Shaw · WordPress & WooCommerce Developer Wellington, New Zealand

👋 Not available for new client work right now!

Running Docker on WSL

I'm all-in on the weirdo m̷͉̘̟͌͗͒ả̴̗͚͍g̴͙̞͆̓̈́î̴̹͎̆̾̚͝c̷̢̪̰͈̊ that is the Windows Subsystem for Linux, and... so far, so good.

My interest in this was finally piqued after spending all of December 2017 working with Docker containers on an actual Linux OS, as some form of ritual therapy to help grieve my dear recently-departed cat, Minerva: (≚ᄌ≚)ℒℴѵℯ❤.

Anyway… with the WSL approach I quickly hit a few surmountable issues getting Docker containers running as required. Solutions to each of the following issues are a simple search away—once the problem itself has been identified, of course—but here they are in one place, for my specific use-case.

You'll need to have enabled and configured WSL in order to hit the following issues in the first place. To get to this point, follow this smart guy's experience.

Docker daemon is unavailable

That vision you have of sandboxing development tools within a crisp Linux terminal? Let it go.

As explained here the Docker daemon must run on the host system, partitioning it from the CLI. The easy way to let the daemon and CLI communicate is to install Docker for Windows. There, in Settings > General, you'll find an option to "Expose daemon on tcp://locahost:2375 without TLS". Tick this.

Next, add the following to ~/.bashrc:

export DOCKER_HOST=tcp://0.0.0.0:2375

This sets a value for the DOCKER_HOST environment variable, with "export" exposing it to child processes via the WSL environment. If it doesn't seem to be working, close and re-open the shell.

Dev domain not resolving

Remember to set the local DNS via your Windows hosts file at C:/ Windows / System32 / drivers / etc / hosts:

127.0.0.1 localhost project.test

…with project.test as the dev domain in this example.

File storage volumes not working

The first time I spun up my project images, the volume I specified to persist a WordPress theme folder appeared not to mount; or, at least, it was not visible. As discussed here, this turns out to be disaccord between Docker for Windows and WSL, in a way that feels slightly contradictory to one of the first things everyone learns about WSL: the entry point for the Windows C: drive is at /mnt/c. However, Docker for Windows mounts at /c.

Per the previous link, a simple workaround is to bind the WSL path to the Docker for Windows one:

$ sudo mkdir /c $ sudo mount --bind /mnt/c /c $ cd /c/path/to/project $ docker-compose up -d

The key point here is to ensure docker-compose is run via the bind mount path.

Dockerfile

Example repo here: A WordPress development environment with Docker Compose on WSL.

π