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.
The Docker daemon always runs as the root user. If you don't want to preface the docker command with sudo , create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.
Running Docker commands with sudo ensures that the Docker command is executed with the security rights of root (by using sudo) or by a user who is a member of the docker group. In this quick tutorial, we'll learn how to run Docker commands without sudo.
Advantages. It consumes the minimum memory needed to run Docker Daemon (Docker server). It's faster than Docker Desktop because it's running directly inside the WSL 2 instance instead of on a separate Linux instance.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With