Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidwudv opened this issue Dec 4, 2019 · 13 comments
Labels

Comments

@davidwudv
Copy link

davidwudv commented Dec 4, 2019

  • Your Windows build number: 19033.1

  • What you're doing and what's happening:

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

  • What's wrong / what should be happening instead:
    Can't access docker service using 'localhost' on windows.
@davidwudv davidwudv changed the title Can't connect to docker swarm container's published port using 'localhost' on windows [WSL2] Can't connect to docker swarm container's published port using 'localhost' on windows Dec 4, 2019
@timesnewmen
Copy link

timesnewmen commented Dec 5, 2019

Same issue here.

@wjsgzcn
Copy link

wjsgzcn commented Apr 15, 2020

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

'docker-compose up' is ok.

@wjsgzcn
Copy link

wjsgzcn commented Apr 17, 2020

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
Copy link

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

@davidwudv
Copy link
Author

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
Copy link

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

@th0ger
Copy link

th0ger commented Jun 21, 2022

Experiencing this still.

@Winfle
Copy link

Winfle commented Feb 21, 2023

Still have the issue

@viniciusxyz
Copy link

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

@magnusriga
Copy link

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

@omid9h
Copy link

omid9h commented Nov 4, 2023

Experiencing this issue too.

@chanpreetdhanjal
Copy link

Try downloading latest version of WSL following the link below

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

@nmcdtu
Copy link

nmcdtu commented Jun 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests