You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WSL2] Cannot access windows service running on host from a container using host.docker.internal #6364
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):
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.
Simon Ferquel (@simonferquel) indeed it does seem to resolve properly without the --add-host as it resolves to another IP and does work!
Working without, resolving to 192.168.65.2
PS C:\Users\User> docker run -it --rm alpine sh -c "apk add curl; curl -X HEAD -vvv http://host.docker.internal:8080"
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20191127-r4)
(2/4) Installing nghttp2-libs (1.41.0-r0)
(3/4) Installing libcurl (7.69.1-r3)
(4/4) Installing curl (7.69.1-r3)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 7 MiB in 18 packages
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
* Trying 192.168.65.2:8080...
* Connected to host.docker.internal (192.168.65.2) port 8080 (#0)
> HEAD / HTTP/1.1
> Host: host.docker.internal:8080
> User-Agent: curl/7.69.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< server: ecstatic-3.3.2
< Content-Type: text/html
< etag: W/"562949953516050-0-2020-12-21T11:31:34.262Z"
< last-modified: Mon, 21 Dec 2020 11:31:34 GMT
< cache-control: max-age=3600
< Date: Mon, 21 Dec 2020 17:54:49 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
* no chunk, no close, no size. Assume close to signal end
<
* Closing connection 0
Broken using the CLI flag, resolving to 192.168.65.1
PS C:\Users\User> docker run -it --rm --add-host=host.docker.internal:host-gateway alpine sh -c "apk add curl; curl -X HEAD -vvv http://host.docker.internal:8080"
>>
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20191127-r4)
(2/4) Installing nghttp2-libs (1.41.0-r0)
(3/4) Installing libcurl (7.69.1-r3)
(4/4) Installing curl (7.69.1-r3)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 7 MiB in 18 packages
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
* Trying 192.168.65.1:8080...
* connect to 192.168.65.1 port 8080 failed: Operation timed out
* Failed to connect to host.docker.internal port 8080: Operation timed out
* Closing connection 0
curl: (28) Failed to connect to host.docker.internal port 8080: Operation timed out
Behavior seems wrong so I'll let that open for now.
r=adapter.send(request, **kwargs)
File"/opt/bitnami/python/lib/python3.8/site-packages/requests/adapters.py", line516, insendraiseConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=30002): Maxretriesexceededwithurl: /api/v1/datastore/write (CausedbyNewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fdbccf2e130>: Failed to establish a new connection: [Errno -2] Name or service not known'))
127.0.0.1-- [18/Feb/202103:48:40] "POST /api/v1/user/ HTTP/1.1"500-
Reacted by Serhii Kovalchuk, Shane St Savage, Rob Rodriguez, aviNrich, kplese and Alexander Markov
This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.
Activity
simonferquel commentedon Dec 21, 2020
You should try without adding the
--add-hostflag (it is not needed on Desktop). We fixed it lately, but not sure if it is in a public build yet.mgcrea commentedon Dec 21, 2020
Simon Ferquel (@simonferquel) indeed it does seem to resolve properly without the
--add-hostas it resolves to another IP and does work!192.168.65.2192.168.65.1Behavior seems wrong so I'll let that open for now.
gomrinal commentedon Feb 18, 2021
Hi There,
I am getting the same error!
microsoft-github-policy-service commentedon Feb 1, 2024
This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.
Thank you!