Skip to content

[WSL2] Cannot access windows service running on host from a container using host.docker.internal #6364

@mgcrea

Description

@mgcrea

Environment

Windows build number: 10.0.19042.572
Your Distribution version: lsb_release: not found
Whether the issue is on WSL 2 and/or WSL 1: Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020

It's running on a clean Windows10 install followed by a docker desktop 3.0 setup and a docker-compose up -d.

Steps to reproduce

Start a service on the windows host:

npm i -g http-server
http-server -p8080

Run a container with a bind on host-gateway:

docker run -it --rm --add-host=host.docker.internal:host-gateway alpine

Try to curl the windows host inside (/etc/hosts properly has 192.168.65.1 host.docker.internal):

curl http://host.docker.internal:8080

Expected behavior

Working access according to the WSL docs: Accessing Windows networking apps from Linux (host IP)

So not sure if the docs are outdated (WSL1?) or if I have something misconfigured but this is on a clean install and with Windows Defender turned off.

Actual behavior

/ # curl http://host.docker.internal:8080
curl: (28) Failed to connect to host.docker.internal port 8080: Operation timed out

Does work if I use the vEthernet (WSL) ip (eg. curl http://172.27.64.1:8080), but since it changes at every restart and I haven't found a reliable way to expose this IP address to my container, I'm stuck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions