microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
16.94k stars 799 forks source link

[WSL2] Can't connect to docker swarm container's published port using 'localhost' on windows #4729

Open davidwudv opened 4 years ago

davidwudv commented 4 years ago

When I run this command:

docker run -d -p 80:80 nginx

Everythin is ok, I can access the nginx service using http://localhost:80 on windows browser.

But when I using docker swarm service:

version: '3.3'

services:
  nginx:
    image: nginx
    ports:
      - target: 80
        published: 80
        protocol: tcp
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
            condition: on-failure

Create docker stack:

 docker stack deploy --compose-file=nginx.yaml nginx

I can't use 'localhost' to access the nginx service on windows. Screenshot_20191204125208

But the localhost port is opening: Screenshot_20191204125221

timesnewmen commented 4 years ago

Same issue here.

wjsgzcn commented 4 years ago

Same issue with exactly the same yml file running with 'docker stack ...'.

'docker-compose up' is ok.

wjsgzcn commented 4 years ago

Finally, I find the solution of this problem: in wsl2 terminal, run 'ifconfig' to check your IP address of 'eth0', in my case the address is '172.22.182.119', visit this address instead of 'localhost', and every thing is ok now.

Hope Microsoft can resolve this problem, and we can visit localhost instead of the internal address of wsl2.

JeanRessouche commented 4 years ago

Hi, is there any progress on this issue ?

no way to reach the service, even from the wsl2 distro ip

davidwudv commented 4 years ago

Hi, is there any progress on this issue ?

  • docker run -p 80:80 nginx 🆗
  • docker-compose up on the below file 🆗
  • docker stack up on the below file ❌

no way to reach the service, even from the wsl2 distro ip

@souchprod The problem is still not solved

FrankAtHexagon commented 3 years ago

Has this issue been solved? My team is experiencing a similar issue.

th0ger commented 2 years ago

Experiencing this still.

Winfle commented 1 year ago

Still have the issue

viniciusxyz commented 1 year ago

A few months later and I still have the same problem.

magnusriga commented 1 year ago

Same here. Does this mean it is currently not possible to use Swarm mode on WSL?

omid9h commented 8 months ago

Experiencing this issue too.

chanpreetdhanjal commented 8 months ago

Try downloading latest version of WSL following the link below

https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/

nmcdtu commented 3 weeks ago

My colleague found a solution: replacing the ports section in docker-compose.override.yaml with the below, then it should work with localhost:8000 from Windows (provided that the port is 8000)

    ports:
        - target: 8080
          published: 8000
          protocol: tcp
          mode: host

Tested with Windows 11 10.0.22631.