Ubuntu WSL with docker could not be found

Viewed 125673

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

18 Answers

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

enter image description here

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.

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://docs.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

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

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.

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.

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

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.

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

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.

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

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.

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

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

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

In my case my distribution was running in WSL 1 mode

To check the WSL mode, run:

wsl.exe -l -v

To upgrade your existing Linux distro to v2, run:

wsl.exe --set-version (distro name) 2

To set v2 as the default version for future installations, run:

wsl.exe --set-default-version 2

Related