153

The command $ docker could not be found in this WSL 1 distro. We recommend to convert this distro to WSL 2 and activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

Not able to change to WSL2 and not able to install docker:

docker wls

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
suki
  • 1,531
  • 2
  • 6
  • 4
  • 1
    Did you `apt install` docker within your WSL environment? You're going to need to install full docker for your windows OS, and then install the docker CLI tool within your WSL environment, pointing WSL's docker at your host machine's docker port. This should help: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly – Taylor Reece Aug 20 '20 at 03:53
  • 1
    I get the same error occationally. The problem always solves itself after I go to docker desktop and press the update button. Maybe that helps somone. – java lava Mar 03 '22 at 10:48
  • I needed this because everything in my container's bash executed really slowly. So in my case I had open "Ubuntu for Windows" and execute `explorer.exe .` which opened a network folder in which I had to copy all my projects from "c:\dev" ie. from Windows filesystem. After that nothing worked, and Fabrício's [answer](https://stackoverflow.com/a/65904006/9583480) saved the day. Then in Ubuntu for Windows I executed `cd dev/gitlab.mycompany.com/my-project/sub-project` and then `code .` opened WSL version of my project in VS Code. Rebuilt docker containers and everything now works smoothly. – s3c Mar 24 '22 at 10:05
  • Often the problem that leads me to this Google Search is very simple: I forget to start Docker Desktop :) – s3c Apr 12 '23 at 10:04

23 Answers23

228

You need to go to the docker desktop settings, and enable integration with your distro in "Resources -> WSL Integration".

enter image description here

pushStack
  • 3,315
  • 1
  • 15
  • 14
  • 4
    Only worked after installing `wsl_update_x64.msi`. See step 3 here https://docs.docker.com/docker-for-windows/wsl/#prerequisites – Dizzy Feb 14 '21 at 00:08
  • 1
    I do not have the WSL Integration on my Docker Desktop app, Do I have to upgrade the Docker desktop to get the WSL Integration feature? – Livhu Feb 25 '21 at 08:27
  • @pushStack I have the same problem. I installed both WSL 2 and Docker desktop the date of this posting and it still refuses to appear. – Woodsman Jun 30 '21 at 03:40
  • This may be obvious to others, but in addition to the Fedora/Ubuntu/XXX Linux distro you choose, Docker will also install/create WSL distros: – Woodsman Jun 30 '21 at 04:03
  • 2
    This may be obvious to others, but in addition to the Fedora/Ubuntu/XXX Linux distro you choose, Docker will also install/create WSL distros docker-desktop and docker-desktop-data. You might need to run & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon in PowerShell. I had to "SwitchDaemon"s twice, the first time to enable me to go to Docker Desktop settings, but it didn't show the WSL integration. So I ran "SwitchDaemon" again, and it was willing to show WSL integration. I had to go through this because of some irritating system update. – Woodsman Jun 30 '21 at 04:10
  • 2
    Had to do this before mine started working: Open Docker Desktop and click on the 'troubleshoot' icon in the top right corner. Click 'Clean/Purge Data' and select 'WSL 2' only and click 'delete'. Restart docker. docker-desktop-data was Stopped before that. – Superdooperhero Feb 14 '23 at 11:42
  • man of the day!!!! this problem ChatGPT couldn't answer – Karam Qusai Aug 14 '23 at 20:23
115

Assuming you already have wsl 2 in your system, run powershell as admin:

run wsl --list --verbose which will give you a list of your wsl running processes:

> wsl --list --verbose
  NAME                   STATE           VERSION
  Ubuntu-20.04           Running         1

Then to switch it with wsl --set-version <your proc> 2:

> wsl --set-version Ubuntu-20.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.
Joey Baruch
  • 4,180
  • 6
  • 34
  • 48
96

My problem seems like it's the same, despite the integration WSL is already enabled since installation.

In the windows shell:

> wsl docker --version

The command 'docker' could not be found in this WSL 2 distro.
We recommend to activate the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

An option to resolve this problem is reinstalling Docker Desktop (https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon#how-to-uninstall-docker), but don't need to do this.

The steps below work for me (I found at https://github.com/docker/for-win/issues/7039).

Open windows shell (maybe as admin), and run:

> wsl -t docker-desktop
> wsl --shutdown
> wsl --unregister docker-desktop

Then go to windows services, stop the Docker Desktop Service, OR to do this running the command in windows shell as admin:

> Stop-Service -Name "com.docker.service"

And finally, restart the Docker Desktop App.

Test in the windows shell:

> wsl docker --version
Docker version 20.10.2, build 2291f61
Fabrício Pereira
  • 1,521
  • 1
  • 12
  • 20
17

I stuck with this error after remove Ubuntu 18.04 and install the 20.04.

Even with the WSL 2 enabled, I still face this error.

This is what works for me, go the Settings --> resource and toggle the "Ubuntu" then the error disappear :)

enter image description here

raynus
  • 195
  • 2
  • 8
11

For me, nothing worked excepted : right click on running Docker icon (next to clock) and chose "Switch to Linux containers"

enter image description here

And here we go ! Now i can have the menu Settings > Resources > WSL integration.

Aurel
  • 338
  • 2
  • 13
11

For me running the following command in wsl terminal worked:

sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce
sudo apt-get install docker-compose
sudo apt-get upgrade

Source: https://www.srcmake.com/home/fabric

AP.
  • 8,082
  • 2
  • 24
  • 33
faisal
  • 111
  • 1
  • 4
7

WSL Integration under Resources was not showing for me.

I had to uncheck "Use the WSL2 based engine" under General settings, Apply, then Check it again, Apply, then WSL Integration showed up under resources and I could click the Ubuntu slider.

r590
  • 689
  • 1
  • 10
  • 15
6

For those still having issues with this, some of my symlinks magically vanished and no amount of reinstalling helped.

Make sure you have the following symlinks in your WSL2 installation:

$ ls -l /usr/bin/ | grep docker
lrwxrwxrwx 1 root   root          56 Jul 14 13:01 com.docker.cli -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/com.docker.cli
lrwxrwxrwx 1 root   root          48 Jul 14 13:01 docker -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
lrwxrwxrwx 1 root   root          56 Jul 14 13:01 docker-compose -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-compose
lrwxrwxrwx 1 root   root          59 Jul 14 13:01 docker-compose-v1 -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-compose-v1
lrwxrwxrwx 1 root   root          71 Jul 14 13:01 docker-credential-desktop.exe -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-credential-desktop.exe
lrwxrwxrwx 1 root   root          50 Jul 14 13:01 hub-tool -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/hub-tool
lrwxrwxrwx 1 root   root          48 Jun 29 09:27 notary -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/notary
agentgonzo
  • 3,473
  • 3
  • 25
  • 30
  • Any idea on why/how this happens? I don't think my setup had symbolic links under `/usr/bin` but its obviously a work-around. I read through the `docker` (not `docker.exe`) file /mnt/c/Program Files/.... and it is a shell script that checks /usr/bin for docker – tijko Apr 12 '22 at 15:20
  • No idea. Sorry. I just found the above missing symlinks and it fixed it. – agentgonzo Apr 13 '22 at 16:09
5

I had this issue, for me running

$ ls -l /usr/bin/ | grep docker

showed all the correct symlinks as per this answer however I saw the following:

which docker
/mnt/c/Program Files/Docker/Docker/resources/bin/docker

The fix was to simply to set the PATH variable to have /user/bin as the first entry

PATH="/usr/bin:$PATH"

From the multitude of answers, it seems like there are many things that can cause this error, so your mileage may vary.


Another good thing to check is that Docker Desktop is actually running. If it isn't, which docker will result in the /mnt/c/... directory as above.

dav_i
  • 27,509
  • 17
  • 104
  • 136
4

As Taylor wrote in his comment you need to connect from WSL to docker desktop.
In the image you attached there is a check box expose daemon on ... Check this box.
Now you need docker cli, you can install Linux vm then install docker in that Linux vm you just installed.
Then run which docker and copy this file to your windows computer.
Copy the docker executable into /usr/local/bin on your WSL.
Now run the following in WSL

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc
. ~/.bashrc

This worked for me on WSL 1.

Here is guide I found on the all process

Shmuel
  • 1,568
  • 10
  • 20
4

In my case, the integration was correctly set in the docker-app, WSL2 was correctly the default wsl, and I wasn't able to solve unregistering the wsl docker instance and restarting the docker service like mentioned in other answers.

After some time, I noticed that the command docker-compose successfully worked. The issue was limited to the docker command.

I looked for all docker commands in the directory usr/bin, that is the path where docker-compose is located (which docker-compose), so runnining ls -l /usr/bin | grep docker, I found

drwxrwxrwx  1 root   root          48 Nov 29 10:59 docker
lrwxrwxrwx  1 root   root          56 Nov 29 10:59 docker-compose -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-compose*
lrwxrwxrwx  1 root   root          59 Nov 29 10:59 docker-compose-v1 -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-compose-v1*
lrwxrwxrwx  1 root   root          71 Nov 29 10:59 docker-credential-desktop.exe -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-credential-desktop.exe*
lrwxrwxrwx  1 root   root          50 Nov 29 10:59 hub-tool -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/hub-tool*

For some weird reason, docker wasn't a symbolic link but a directory.

I solved removing the directory and re-creating manually the symbolic link:

rm -rf /usr/bin/docker
sudo ln -s /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker /usr/bin/docker
Fabio Formosa
  • 904
  • 8
  • 27
  • Great it help, also met next problem with exec `com.docker.cli executable file not found in $path` which could be solve with alternative command addresing to cli **com.docker.cli** `sudo ln -s /mnt/wsl/docker-desktop/cli-tools/usr/bin/com.docker.cli /usr/bin/docker` – Andrzej Krawczuk Feb 10 '22 at 12:44
3

Fabrício Pereiras answer was working for me, but I had to do it pretty often, which was still annoying. Turns out the order of starting the systems is important too.

Start Docker first, then WSL2 after.

I don't start Docker Desktop with Windows and usually had opened a terminal in WSL already. Then Docker could not be found. Fabricios answer was working for me because I shutdown WSL2, then started it again when Docker was already running.

MrSnoozles
  • 860
  • 8
  • 13
  • This is exactly what I do however came here to find another solution if I am running wsl and can not restart for docker? is there any? – Sayyed Dawood Dec 22 '21 at 04:19
2

I followed theses steps: https://learn.microsoft.com/en-us/windows/wsl/install-win10

Also, for docker into ubuntu, I enabled it in docker resources as a final step. Settings > Resources > WSL Integration. from: https://docs.docker.com/docker-for-windows/wsl/

BBeau
  • 51
  • 3
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference – Prathamesh More Sep 26 '20 at 03:33
2

Make sure that you have a distro that is compatible with wsl2:

https://ubuntu.com/wsl

enter image description here

Leon Africa
  • 509
  • 6
  • 11
2

I was experiencing the same issue with Ubuntu-20.04 (WSL2) and Docker Desktop (v4.11.1). For me, WSL integration and other flags are all set but still I was getting:

The command 'docker' could not be found in this WSL 2 distro.

I followed @r590 's method. I turned-off and then turned-on WSL Integration under:

Resources > WSL Integration

and then it worked for me.

1

Sometimes the simplest solution is the most effective solution, if you are installing docker desktop for the first time make sure you restart windows for the effects to take change. This is not guaranteed to work but it is always worth a shot.

A Merii
  • 574
  • 9
  • 21
1

I rebooted my machine and docker stopped working. I reinstalled docker-desktop and did all the suggestions and nothing worked.

I found that I had a directory here /usr/bin/docker. I deleted it and then reinstalled docker which fixed the issue.

Community
  • 1
  • 1
Lewis
  • 11
  • 1
1

I had the same problem The error:

The command 'docker' could not be found in this WSL 2 distro. We recommend to activate the WSL integration in Docker Desktop settings.

The solution: Upgrading the desktop-docker version

  1. If updates are available, When you navigate to the Docker Dashboard, you will be able to click on Download Updates as shown below.

enter image description here

  1. enter image description here

  2. enter image description here

tzur
  • 33
  • 6
  • Hi, please add supporting informations. Also,, please read [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/a/285557/7353417). Thank you – pierpy May 07 '23 at 10:35
0

I was having the same issue, however, for me, I installed docker using a different Windows account (admin) because my default account (under a domain) is a standard user and has no admin access.

After installing docker, I started docker and got an error that I'm not part of the docker-users group so I started docker using the admin account that I have. Docker started but it's not able to see the WSL integration. Similar to the screenshot below.

Docker config missing WSL integration

What fixed it for me is to add the domain account to the docker-users and restart my machine. After that WSL is visible in the configuration.

# For local account
net localgroup docker-users "your-user-id" /ADD

# For domain account
net localgroup docker-users "DOMAIN\your-user-id" /ADD

Docker config showing the WSL integration

Renzo Sunico
  • 141
  • 2
  • 6
  • The commands can only be executed using Admin rights. And typically, after installation the user is already part of the localgroup... This doesn't work for me. I only get the error after the PC is woken after standby. – jaques-sam Mar 01 '23 at 07:35
0

The error shows that you're using WSL version 1.

To change it to 2, open PowerShell and run

wsl -l -v

WSL versions

You should see a number 1 near Ubuntu (or something similar).

To change that to version to 2, simply run

wsl --set-version Ubuntu 2

and you'll see something like

Conversion in progress from wsl1 to wsl2

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
0

In WSL2 I've installed the docker service, using these instructions: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository.

So in my WSL2 Ubuntu environment I have the docker service running. I have no need for the desktop interface, the docker instances are containers for services.

It works generally, but often I forget to 'sudo start service docker' (I need to upgrade my linux sysadmin skills to get the service to start properly with the instantiation of WSL2 environment)

(FWIW: This really should simply be a comment, but I lack the requisite qualifications at the moment...)

LJM
  • 1
  • 2
-1

Switch to linux containers in docker desktop then it will work.

sadiq rashid
  • 468
  • 5
  • 8
-2

You need to run the WSL console as Admin. If not, the docker command may be not recognized.

Jöcker
  • 5,281
  • 2
  • 38
  • 44
  • 1
    There is no case that I can think of where running WSL as Admin is the correct solution. Running WSL as Admin has security implications, and should typically be avoided unless you absolutely need to access some resource in Windows with elevated permissions. But in doing so, you give any code *running as your WSL user* full access to your Windows host, including modification and removal of system-level files. `sudo`/`root` aren't even needed to modify (or corrupt) your Windows installation when running WSL elevated. – NotTheDr01ds Oct 07 '22 at 12:09