TL;DR
When Docker for Desktop was running on Windows 10, docker that was running on ubuntu of WSL did not work on WSL2 because the environment variable DOCKER_HOST
was specified. It works when unset DOCKER_HOST
.
I was able to use docker with WSL, but it stopped working with WSL2.
$ docker ps [~]
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
Docker is actually running, and you can see in Power Shell that port 2375 is free.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ Test-NetConnection -ComputerName localhost -Port 2375
ComputerName : localhost
RemoteAddress : ::1
RemotePort : 2375
InterfaceAlias : Loopback Pseudo-Interface 1
SourceAddress : ::1
TcpTestSucceeded : True
WSL version check.
$ wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop-data Running 2
docker-desktop Running 2
The WSL version is 2, and docker-desktop is also working.
The cause is that the environment variable DOCKER_HOST
was specified (in my case .zshrc).
export DOCKER_HOST=tcp://localhost:2375
Certainly WSL needed this. However, it is not necessary for WSL2. If you unset this, it will work.
$ unset DOCKER_HOST
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
moved. Congratulations.
I've been in great trouble personally, so I'll keep a record here for those who are in trouble for the same reason.
Recommended Posts