Docker client under WSL2 doesn't work without sudo

Viewed 4269

On WSL2 (Ubuntu 20.04), I'm trying to connect to the Docker daemon that's running on Windows.

$ docker ps
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
(exit code 1)

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
(exit code 0)

Why does it work with sudo, but not without sudo? How can I make it work without sudo?

I have done

$ sudo usermod -aG docker $USER 

which ran successfully, but didn't help with the issue.

I have also restarted everything many times, which didn't help.

1 Answers

Weird solution for this one - but go ahead and try:

unset DOCKER_HOST

And if that works, you can make the fix permanent by going back and commenting out the "export DOCKER_HOST=tcp://localhost:2375" in your .bashrc file. I think it has something to do with how docker is configured in WSL 2 vs. WSL 1, but Docker never updated their documentation to reflect this.

Related