Ubuntu WSL with docker could not be found
DockerWindows Subsystem-for-LinuxDocker Problem Overview
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 Solutions
Solution 1 - Docker
You need to go to the docker desktop settings, and enable integration with your distro in "Resources -> WSL Integration".
Solution 2 - Docker
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.
Solution 3 - Docker
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
Solution 4 - Docker
For me, nothing worked excepted : right click on running Docker icon (next to clock) and chose "Switch to Linux containers"
And here we go ! Now i can have the menu Settings > Resources > WSL integration.
Solution 5 - Docker
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 :)
Solution 6 - Docker
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.
Solution 7 - Docker
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
Solution 8 - Docker
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.
Solution 9 - Docker
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.
Solution 10 - Docker
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.
Solution 11 - Docker
I followed theses steps: https://docs.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/
Solution 12 - Docker
Solution 13 - Docker
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
Solution 14 - Docker
You need to run the WSL console as Admin. If not, the docker command may be not recognized.