So, I’m an occasional developer (and a frequent scripter), so I occasionally need to, well, develop stuff. And quite often I need Docker for packaging whatever I’m trying to push out there, or possibly to run someone else’s containers on my machine.
But sometimes, Docker is more pain than gain. And this, dear reader, was definitely one of those times.
So, what was wrong?
Problem
Alright, so my Docker was having some trouble with WSL. No biggie – except any docker command would always fail with something along the lines of:
Error: Failed to connect to Docker service make sure you have started it. The error was: One or more errors occurred. (The operation has timed out.)
Normally, this is usually caused by Docker (Desktop) Service being stopped for whatever reason – and this can be fixed by starting the service or opening Docker Desktop. But sometimes, this doesn’t help – even if the service starts, you still get the error, and when you open Docker Desktop, you first get an annoying view like this:
And then get an error somewhat like this:
And the same in written form:
Docker Desktop - Unexpected WSL error
An unexpected error was encountered while executing a WSL command. Common causes
include access rights issues, which occur after waking the computer or not being connected
to your domain/active directory.
Please ty shutting WSL down (wsl --shutdown) and/or rebooting your computer. If not
sufficient, WSL may need to be reinstalled fully. As a last resort, ty to uninstall/reinstall
Docker Desktop. If the issue persists please collect diagnostics and submit an issue
(https://docs.docker.com/desktop/troubleshoot/overview/#diagnose-from-the-terminal).
Alright, what to do then?
Solution
There’s a few things you can try. They’ll probably work, so I’ll explain them.
And then, at the end of the article, I’ll tell you what finally worked for me. Because nothing else did.
Promising, right? Let’s get to it.
1. Do as the error message says and restart your stuff
You can try restarting wsl by running wsl –shutdown in Terminal and restarting Docker Desktop. Or just restarting your computer completely. There’s a very real chance it might help.
But if that proves unfruitful, you can try reinstalling wsl completely. It’s more complicated than you might think, but… Still pretty simple 😃
2. Properly reinstall WSL completely
To actually reinstall wsl, you need to first completely and totally remove it by removing all Windows Subsystem for Linux components that you have on your machine. But before you do that, check which distros you have installed for wsl by running this:
wsl -l --all
You should get something like this back:
Make note of your distribution names… Except you can ignore docker-desktop for now.
And then to removing stuff!
Unless you have been using wsl since 2016, you should be able to remove all components by navigating to “Add or Remove Programs” in Windows and searching for “Linux” or “Subsystem”. You should see something like below:
And then you can select each, one by one, and uninstall them.
After that, you’ll need to remove the distributions separately. Find them, and remove them.
Next, we’ll finally get to installing wsl again. You can now get it with winget (and if your Microsoft Store works like mine, it’s pretty much the only way to get it) by running this (first confirm it’s available, then install):
winget search "Windows Subsystem for Linux"
winget install "Windows Subsystem for Linux"
Don’t run “winget install wsl”. That’s a trap – it’ll install wsl v1, and you want wsl v2.
Anyway – when you’re done with that, you can install a Linux distribution to use. Ubuntu is one example, and you can get it, too, with winget:
winget install "Ubuntu 22.04 LTS"
Or by clicking here: ms-windows-store://pdp?hl=en-us&gl=us&productid=9PN20MSR04DW&mode=mini&pos=4%2C3%2C2468%2C1379&referrer=storeforweb
Click “Get” and it’ll install.
Anyway – after installing your favorite distribution, you need to run it once to finalize configuration.
And then you should be good to retry starting Docker Desktop again. With some luck, you’re good now.
Oh, still not working? Well, the last thing is what finally worked for me…
3. Disable wsl integration in Docker Desktop
This is a bit depressing… But it helped.
I mean, it won’t help if you if you actually need to run your Docker containers in wsl… But if you don’t care and just need to get Docker up and running, here’s how to quickly solve it:
How to disable wsl integration in Docker Desktop?
- Open Docker Desktop and navigate to Settings
- Un-tick the box “Use the WSL 2 based engine”
- Click “Apply & restart”
- Run your Docker commands again!
And now, it should all just work (except for wsl-dependent stuff).
Depressing, right?
- “Performing cleanup” – Excel is stuck with an old, conflicted file and will never recover. - November 12, 2024
- How to add multiple app URIs for your Entra app registration? - November 5, 2024
- How to access Environment Secrets with GitHub Actions? - October 29, 2024