· 4 Min read

Docker Desktop 2.3 & Alpine WSL 2 Integration

Post Seeing that most docker images are built on Alpine these days, I wanted to recreate the same exact production environment during development by integrating Docker Desktop and Alpine (via WSL2). Most online posts detail getting Ubuntu WSL working, but very few touch on Alpine, and the ones that do I struggled to get working (kept getting the dreaded “cannot connect to the docker daemon at unix ///var/run/docker.sock” error). Then I found the solution (skip to step #7), but I’ll start from the beginning for those who have yet to embark on this journey:

  1. Install & Enable WSL2
    1. Install WSL [cmd]:
      “dism.exe /online /enable-feature /featurename:Microsoft-Windows–Subsystem-Linux /all /norestart”
    2. Update to WSL2 [cmd]:
      “dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart”
    3. Update the WSL2 linux kernel msi package
    4. Set WSL2 as your default version [cmd]:
      “wsl –set-default-version 2″
    5. Restart your PC for the WSL subsystem to take effect.

      Note: There is a known conflict between Intel Display Audio and Hyper V that will prevent sound from working correctly. The current workaround is to set your active playback device to ’24 bit, 441000 Hz (Studio Quality)” and the sound will automagically work again. Dell U3415W Properties

  2. Install Docker Desktop 2.3
    1. WSL2 based engine should automatically be selected during installation.
    2. Once installation is complete, you will be required to logout/login again. Go ahead and do that.

      Note: If you’re experiencing an “com.docker.cli: executable file not found in %PATH%” error on login, the fix is to add “C:\Program Files\Docker\Docker\resources\bin” to the system PATH. Log out/in again and it should start up normally.

At this point, Docker should startup upon login and work properly. You can stop here if you just want to start integrating it into your various IDEs, but if you’d like to install a Linux distro with synchronized Docker repositories, then read on. I’m using Alpine Linux as an example below.

  1. Once logged in, Go to the Microsoft Store (Yes, that one) and install “Alpine WSL”. It should install v3.11.3 as of this post.

    • Tip: If you ever need to reset this install, you can do so in Start > Settings >Apps > Alpine WSL > Advanced Options > Reset
  2. Start Alpine WSL’s initial setup by going into Start > “Alpine WSL” and complete the user/pass setup (This same pass can be used for su).

  3. In Alpine, su into root (sudo isn’t installed- you can do this as a side exercise) and install these packages:

    1. glibc: glibc isn’t in the official repos, but it’s a required dependency for the docker proxy to work. You can get it here
      1. Add the repo maintainer’s key: “wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub”
      2. Get the latest glibc package: “wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk”
      3. Install glibc: “apk add glibc-2.32-r0.apk”
    2. docker-cli: You don’t need full-blown docker engine, just the client:
      1. Install docker-cli: “apk add docker-cli”
      2. If you try “docker info”, it should give you the “cannot connect to the docker daemon…” message. This is normal (the engine isn’t installed in this container, remember?)
    3. exit and close Alpine WSL cli window.
  4. Switch back to Docker Desktop. Go into Settings > Resources > WSL Integration. This enables the docker proxy to work in your distro of choice. Docker Desktop Settings

    1. Make sure “Enable integration with my default WSL distro” is checked.
    2. Switch on the “Alpine” toggle.
    3. Click Apply & Restart (this restarts docker the docker engine)
  5. Start “Alpine WSL” again from the start menu and try the “docker images” command.

    1. If you’re still getting the “cannot connect to the docker daemon…” message, that means your docker-cli can’t find your docker engine (your /var/run/docker.sock symlink is broken).
      • The fix: “sudo ln -sf /mnt/wsl/docker-desktop/shared-sockets/guest-services/docker.sock /var/run/docker.sock”
    2. Try “docker images” again. This time, it should return and empty list, which should be the same as the list on windows.
      1. Alpine cli: Alpine CLI
      2. Windows cli: Windows CLI
  6. Crack open a favorite beverage of your choice and celebrate. You’re done.

Now both environments are interacting with the same docker engine, and you can start/continue your container based development.