Docker does not work when DOCKER_HOST is specified in WSL2

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.

phenomenon

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.

reference

Recommended Posts

Docker does not work when DOCKER_HOST is specified in WSL2
MySQL container does not start in Docker
Behavior when wild card (**) is specified in ruby
When @Transactional of Spring Boot does not work
@BeforeStep does not work in Tasklet of spring-batch
When the project is not displayed in eclipse
Sidekiq-limit_fetch does not work
Localhost3000 does not start up in Docker / Rails development.
When Docker for Mac 2.4.0.0 does not reflect file changes
Correspondence when Ruby version does not switch in rbenv
Hivernate Validator does not work in WAS Liberty environment
[Railways] Railways does not work when the RubyMine project root is other than the Rails root directory.
Processing when an ID that does not exist in the database is entered in the URL
"Do not show again" check does not work in the warning dialog when starting applet
Docker for Windows: MySQL container does not start when migrating from Hyper-v to WSL2
When there is no output to stdout in docker log
When a breakpoint is set in IntelliJ IDEA but it does not stop in debugging [Gradle]
When rewriting the CMD of docker image of Pod in the manifest of k8s, command is not good
Exit code 1 occurs when Rails is stopped in Docker environment
What to do when Rails on Docker does not reflect controller changes in the browser
Check the behavior when the exception specified by expected in JUnit 4 @Test annotation occurs / does not occur
Handling when calling a key that does not exist in hash
The repository ... is not signed error in docker build apt-get update
WSL2 + Docker Desktop for Windows does not launch only MySQL container
Docker test DB does not start
Disable display when not logged in
Data is not registered in Rails.
Pay.JP Solution when it can be done locally but it does not work well in the production environment
[Help] Docker for windows 2.3.0.4 without login Service startup method does not work [Help]
When the form such as Select of Materialize does not work properly
If the JDK version is correct in Eclipse but an error occurs or the compiler does not work properly
[Rails] Annotate is not executed when migrating
eclipse tab width change does not work.
JavaScript (vanilla) does not respond in Rails.
Image flew when updating Docker with WSL2
.sql file does not run in docker-compose
Image is not displayed in production environment
Do not return when memoizing in Ruby
When UITextView is not displayed (Swift, Xcode)
Try putting Docker in ubuntu on WSL
[NetBeans] Story when it does not start
What to do when rails db: seed does not reflect in the database
File manager does not start when logging in again in Docker's LXDE desktop environment
Code written in Java-TeraPad starting from beginner does not work due to error
When nginx conf is not reflected well in AWS Elastic Beanstalk + Rails environment
How to set when "The constructor Empty () is not visible" occurs in junit
If the ctrl + shortcut does not work in Eclipse, disabling welcome may help
What to do when is invalid because it does not start with a'-'
Cause of is not visible when calling a method of another class in java
[Rails] If CSS is not applied in collection_select, check if class can be specified.