This post was most recently updated on April 28th, 2022.
2 min read.Okay – another one of the topics that I’m explaining probably more to myself than whoever’s reading this later. But that’s why I write this blog, so please bear with me. 🙂
Anyway, onto the actual issue at hand!
I was configuring Docker on WSL on my Windows laptop for development purposes. That’s supposed to be easy – install WSL, install a distribution, install Docker, switch it to using WSL, fire up your WSL command prompt and run any Docker commands there (or deploy from wherever you’re developing your stuff).
But… It doesn’t always work like that.
Problem
If you get an error like the one below:
Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
I’m sure that this can be caused by quite a few different reasons, but in my case, the cause was clear. My distros were originally created in WSL 1 instead of 2. And hey, you might have the same issue, so read on!
You can verify this by starting your wsl and running this below to query your kernel version:
uname -r
It should show something like the below for WSL 2:
uname -r
5.10.16.3-microsoft-standard-WSL2
Or by just running this in PowerShell or cmd:
wsl --list --verbose
If you get something like this:
You need to update to version 2. Let’s take a look at how to do that!
Solution
Well, this is actually very straightforward. You’ll need to run this in PowerShell or cmd:
wsl --set-version [distroname] 2
A sample, in line with my screenshot above, would be like this:
wsl --set-version Ubuntu-20.04 2
You need to run it for each distro you have (and want to update).
That’s it! Hope it applies to your case as well – let me know in the comments section below!
References
- WSL version differences: https://docs.microsoft.com/en-us/windows/wsl/compare-versions
- 2024 Year Review – and 20 years in business! - December 31, 2024
- Merging on GitHub Actions fails with “could not read Username for ‘https://github.com’: No such device or address”? - December 24, 2024
- How to close the Sidebar in Microsoft Edge - December 17, 2024