Sudo required for WSL2

Hello,

I recently upgraded from WSL1 to WSL2. I had an existing distribution of Ubuntu 20.04 which I converted to WSL2. After converting to WSL2 I installed docker desktop following the instructions here.

When I run docker desktop and I have a WSL2 terminal open at the same time, this is what I see in powershell when I do wsl -l -v.

NAME                      STATE                        VERSION
*Ubuntu                   Running                      2
docker-desktop            Running                      2

I’ve also gone into my docker desktop settings and ensured it is using the WLS2 backend and I specified integration with Ubuntu. Here is what it looks like:

My problem is that all the commands for docker require sudo. In order to use them regularly (without sudo) I have to enter unset DOCKER_HOST in the terminal. That fixes it but it has to be done every time which doesn’t seem right. I also made sure my username is added to the docker group on both linux and windows sides but still the issue persists.

Does anyone have any clues on how to fix this? Why should I have to use sudo for every command if I have integration enabled? Does it have to do with the missing version number in the integration panel shown above? I’ve tried the Refetch distro and it did nothing.

I am on Windows 10 if it matters.
Docker version is v4.36.0.
WSL2 version is 2.3.26.0.

Edit 1: Not sure if it matters but I realize now that somehow the environment variable DOCKER_HOST is being set to tcp://localhost:2375 at the start of every WSL2 session. Its not in my .bashrc though so I’m really confused where it is coming from. Could that be the issue though?

I’m an idiot.

There was a residual DOCKER_HOST=tcp://localhost:2375 at the bottom of my .bashrc, left over from when I was trying to get docker to work with WSL1. I removed this and now it works as expected.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.