Connect to a Docker Daemon on Windows 10

The Docker for Desktop installation on Windows 10 ignores the hosts setting, so you can't directly use DOCKER_HOST from outside the machine. There's a container that sets this up automatically, though, so this is possible without too much extra effort. This assumes that Docker for Desktop is using the WSL2 engine, not the Hyper-V one.

# In WSL
❯ docker run -d \
		    --name docker-remote-api \
		    -p 2377:2375 \
		    --restart unless-stopped \
		    -v /var/run/docker.sock:/var/run/docker.sock \
		    jarkt/docker-remote-api
		    
# In an elevated Windows (powershell/cmd) prompt
# Forward external requests for port 2377 into WSL
# Get `wsl_addr` by running `ip a` inside WSL
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2377 connectaddress=<wsl_addr> connectport=2377

# ExternallyDOCKER_HOST=tcp://10.0.0.9:2377 docker ps
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                    NAMES
ead1ed00d0f5        jarkt/docker-remote-api   "/bin/sh -c 'socat T…"   4 seconds ago       Up 2 seconds        0.0.0.0:2377->2375/tcp   docker-remote-api
Edit