Docker Desktop 2.3 & Alpine WSL 2 Integration
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:
- Install & Enable WSL2
- Install WSL [cmd]:
“dism.exe /online /enable-feature /featurename:Microsoft-Windows–Subsystem-Linux /all /norestart”
- Update to WSL2 [cmd]:
“dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart”
- Update the WSL2 linux kernel msi package
- Set WSL2 as your default version [cmd]:
“wsl –set-default-version 2″
- 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.
- Install WSL [cmd]:
- Install Docker Desktop 2.3
- WSL2 based engine should automatically be selected during installation.
- 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.
-
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
-
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).
-
In Alpine, su into root (sudo isn’t installed- you can do this as a side exercise) and install these packages:
- 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
- Add the repo maintainer’s key: “wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub”
- Get the latest glibc package: “wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk”
- Install glibc: “apk add glibc-2.32-r0.apk”
- docker-cli: You don’t need full-blown docker engine, just the client:
- Install docker-cli: “apk add docker-cli”
- 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?)
- exit and close Alpine WSL cli window.
- 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
-
Switch back to Docker Desktop. Go into Settings > Resources > WSL Integration. This enables the docker proxy to work in your distro of choice.
- Make sure “Enable integration with my default WSL distro” is checked.
- Switch on the “Alpine” toggle.
- Click Apply & Restart (this restarts docker the docker engine)
-
Start “Alpine WSL” again from the start menu and try the “docker images” command.
- 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”
- Try “docker images” again. This time, it should return and empty list, which should be the same as the list on windows.
- Alpine cli:
- Windows cli:
- 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).
-
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.