Docker integration with WSL2 no longer seems to work with Docker Desktop 4.9.0 despite using WSL2 and walking through the required steps

Viewed 381

I have just updated to Docker Desktop 4.9.0 from Docker Desktop 4.8.*.

I have followed this tutorial back when I was on 4.8.*, I could open my terminal, connect to the Ubuntu 20.04 distro and run docker commands such as docker images .

Now that I have updated to 4.9.0 (80466), and restarted my PC, I no longer can run docker commands through bash, despite having walked through the steps in the tutorial multiple times, having uninstalled and reinstalled Docker Desktop and having walked through the same steps yet another time.

Under Settings > General, the checkbox 'Use the WSL2 Based Engine' is enabled.

Under Settings>Resources>WSL Integration, the checkbox Enable Integration with my default distro is enabled. Under the same tab, 'Enable integration with additional distros' slider is also turned on, and I tried turning it on/off again, restarting the docker client, and trying again. Nothing works.

When I open powershell and run wsl.exe -l -v I get:

 wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

which implies I am indeed using WSL2 and not some other version.

I get the following error in bash:

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

For details about using Docker Desktop with WSL 2, visit:

https://docs.docker.com/go/wsl2/

I havent changed anything that could have lead to this behaviour besides from updating the Docker client.

Update 20/06/2022: Running whereis docker in the WSL-terminal I get:

$ whereis docker
docker: /usr/bin/docker /usr/local/lib/docker /mnt/c/Program Files/Docker/Docker/resources/bin/docker /mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe /usr/share/man/man1/docker.1.gz

However, when I then run the command /usr/bin/docker, I get the message 'No such file or directory'.

Another edit: I have learned that /usr/bin/docker is a symbolic link, which in my case keeps breaking, which I have learned by running the command 'file /usr/bin/docker'. It refers to mnt/wsl/[bla bla]/docker.

I think that after updating Docker Desktop, the WSL distro keeps trying to link to the old version of it. Hence I have tried removing all symbolic links to docker I could find, restarting my WSL2 distro, uninstalling Docker Desktop for Windows, and then reinstalling it.

This doesn't solve the issue itself. Which is weird. I have also noticed that apparently it is now important in what order I start my computer: I need to make sure Docker is runnning on windows, and then run a docker command in powershell, like docker ps or whatever, and after this command is successful, I can start my bash-shell and run docker ps there. If I run any docker command before having run the docker command in powershell, I get the same error as I have described in my initial post, and the symbolic links are gone once more.

What is most interesting is that I have installed another seperate distro of Ubuntu 21.04 (I wanted 20.04 but managed to get the wrong version...) and there I do not need to go through all these steps; I can jump into the bash there and run docker commands and it works.

I guess I will move to Ubuntu 21.04 installation later on if the current issue keeps persisting and no other solution is found.

1 Answers

Check if the docker executable is found with the command whereis docker in the WSL shell. When Docker has started, it should point to /usr/bin/docker.

The message you get is generated by the stub docker command that get added by Docker Desktop at the location /mnt/c/Program Files/Docker/Docker/resources/bin/docker (or where Docker Desktop is installed on Windows).

First, try to execute the command /usr/bin/docker directly. If that works, most likely your PATH variable is incorrect somehow.

Update: There is a issue on the GitHub page of Docker Desktop about this problem: https://github.com/docker/for-win/issues/12783

Related