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

Can't access localhost on Windows while running docker on WSL 2 #2568

Closed
2 tasks done
artyommatveev opened this issue Jul 12, 2024 · 9 comments
Closed
2 tasks done

Can't access localhost on Windows while running docker on WSL 2 #2568

artyommatveev opened this issue Jul 12, 2024 · 9 comments
Labels

Comments

@artyommatveev
Copy link

artyommatveev commented Jul 12, 2024

Have you checked that your issue isn't already filed?

  • I read through FAQ and searched through the past issues, none of which addressed my issue.
  • Yes, I have checked that this issue isn't already filed.

Bug description

Hi! I've done everything according to the install.md file (meaning, I haven't changed anything in the docker-related files, for example), but still have a problem with the localhost page in my web browser on the Windows side. The docker container itself runs correctly on WSL 2.

How to reproduce the bug

  1. Go to the INSTALL.md file and do everything according to the "Recommended Approach" subsection.
  2. Clone the repository in a WSL directory.
  3. Move forward by entering your directory and then run two docker commands described in the "Local setup using Docker (Recommended)" subsection.
  4. Open your web browser on Windows and try entering the localhost page http://localhost:8080. In my case, there's only the "This page isn’t working" inscription.

Error messages and logs

The error:
image

The docker ps command output:
image

The docker logs <container_id> command output:

/usr/local/bundle/gems/citeproc-ruby-1.1.14/lib/citeproc/ruby.rb:1: warning: observer was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add observer to your Gemfile or gemspec. Also contact author of citeproc-ruby-1.1.14 to add observer into its gemspec.
  Logging at level: debug
    Jekyll Version: 4.3.3
Configuration file: /srv/jekyll/_config.yml
  Logging at level: debug
    Jekyll Version: 4.3.3
         Requiring: /srv/jekyll/_plugins/cache-bust.rb
         Requiring: /srv/jekyll/_plugins/details.rb
         Requiring: /srv/jekyll/_plugins/download-3rd-party.rb
         Requiring: /srv/jekyll/_plugins/external-posts.rb
         Requiring: /srv/jekyll/_plugins/file-exists.rb
         Requiring: /srv/jekyll/_plugins/google-scholar-citations.rb
         Requiring: /srv/jekyll/_plugins/hide-custom-bibtex.rb
         Requiring: /srv/jekyll/_plugins/remove-accents.rb
         Requiring: jekyll-archives
         Requiring: jekyll-email-protect
         Requiring: jekyll-feed
         Requiring: jekyll-get-json
         Requiring: jekyll-imagemagick
         Requiring: jekyll-jupyter-notebook
         Requiring: jekyll-link-attributes
         Requiring: jekyll-minifier
         Requiring: jekyll-paginate-v2
         Requiring: jekyll-regex-replace
         Requiring: jekyll/scholar
         Requiring: jekyll-sitemap
         Requiring: jekyll-tabs
         Requiring: jekyll-toc
         Requiring: jekyll-twitter-plugin
         Requiring: jemoji
            Source: /srv/jekyll
       Destination: /srv/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
           Reading: /_layouts/about.liquid
           Reading: /_layouts/archive-category.liquid
           Reading: /_layouts/archive-tag.liquid
           Reading: /_layouts/archive-year.liquid
           Reading: /_layouts/bib.liquid
           Reading: /_layouts/cv.liquid
           Reading: /_layouts/default.liquid
           Reading: /_layouts/distill.liquid
           Reading: /_layouts/none.liquid
           Reading: /_layouts/page.liquid
           Reading: /_layouts/post.liquid
           Reading: /_layouts/profiles.liquid
       EntryFilter: excluded /INSTALL.md
       EntryFilter: excluded /package-lock.json
       EntryFilter: excluded /purgecss.config.js
       EntryFilter: excluded /readme_preview
       EntryFilter: excluded /README.md
       EntryFilter: excluded /LICENSE
       EntryFilter: excluded /package.json
       EntryFilter: excluded /lighthouse_results
       EntryFilter: excluded /CUSTOMIZE.md
       EntryFilter: excluded /bin
       EntryFilter: excluded /Gemfile
       EntryFilter: excluded /FAQ.md
       EntryFilter: excluded /Gemfile.lock
       EntryFilter: excluded /docker-compose.yml
       EntryFilter: excluded /Dockerfile
       EntryFilter: excluded /.jekyll-cache
       EntryFilter: excluded /CONTRIBUTING.md
       EntryFilter: excluded /docker-compose-slim.yml
           Reading: _posts/2015-03-15-formatting-and-links.md
           Reading: _posts/2015-05-15-images.md
           Reading: _posts/2015-07-15-code.md
           Reading: _posts/2015-10-20-disqus-comments.md
           Reading: _posts/2015-10-20-math.md
           Reading: _posts/2018-12-22-distill.md
           Reading: _posts/2020-09-28-github-metadata.md
           Reading: _posts/2020-09-28-twitter.md
           Reading: _posts/2021-07-04-diagrams.md
           Reading: _posts/2022-02-01-redirect.md
           Reading: _posts/2022-12-10-giscus-comments.md
           Reading: _posts/2023-03-20-table-of-contents.md
           Reading: _posts/2023-03-21-tables.md
           Reading: _posts/2023-04-24-videos.md
           Reading: _posts/2023-04-25-audios.md
           Reading: _posts/2023-04-25-sidebar-table-of-contents.md
           Reading: _posts/2023-05-12-custom-blockquotes.md
           Reading: _posts/2023-07-04-jupyter-notebook.md
           Reading: _posts/2023-07-12-post-bibliography.md
           Reading: _posts/2023-12-12-tikzjax.md
           Reading: _posts/2024-01-26-chartjs.md
           Reading: _posts/2024-01-26-echarts.md
           Reading: _posts/2024-01-26-geojson-map.md
           Reading: _posts/2024-01-27-advanced-images.md
           Reading: _posts/2024-01-27-code-diff.md
           Reading: _posts/2024-01-27-vega-lite.md
           Reading: _posts/2024-04-15-pseudocode.md
           Reading: _posts/2024-04-28-post-citation.md
           Reading: _posts/2024-04-29-typograms.md
           Reading: _posts/2024-05-01-tabs.md
       EntryFilter: excluded /_pages/about_einstein.md
           Reading: _pages/repositories.md
           Reading: _pages/projects.md
           Reading: _pages/cv.md
           Reading: _pages/404.md
           Reading: _pages/news.md
           Reading: _pages/profiles.md
           Reading: _pages/about.md
           Reading: _pages/dropdown.md
           Reading: _pages/publications.md
           Reading: _pages/teaching.md
           Reading: _pages/blog.md
           Reading: assets/css/main.scss
           Reading: robots.txt
           Reading: _news/announcement_1.md
           Reading: _news/announcement_2.md
           Reading: _news/announcement_3.md
           Reading: _projects/1_project.md
           Reading: _projects/2_project.md
           Reading: _projects/3_project.md
           Reading: _projects/4_project.md
           Reading: _projects/5_project.md
           Reading: _projects/6_project.md
           Reading: _projects/7_project.md
           Reading: _projects/8_project.md
           Reading: _projects/9_project.md
           Reading: _data/coauthors.yml
           Reading: _data/cv.yml
           Reading: _data/repositories.yml
           Reading: _data/venues.yml
        Generating: JekyllGetJson::GetJsonGenerator finished in 0.0001834 seconds.
        Generating: Jekyll::Scholar::DetailsGenerator finished in 2.36e-05 seconds.
Fetching external posts from medium.com:
...fetching https://medium.com/@al-folio/displaying-external-posts-on-your-al-folio-blog-b60a1d241a0a?source=rss-17feae71c3c4------2
Fetching external posts from Google Blog:
...fetching https://blog.google/technology/ai/google-gemini-update-flash-ai-assistant-io-2024/
/usr/local/lib/ruby/3.3.0/net/protocol.rb:43:in `ssl_socket_connect': Net::OpenTimeout (Net::OpenTimeout)
        from /usr/local/lib/ruby/3.3.0/net/http.rb:1674:in `connect'
        from /usr/local/lib/ruby/3.3.0/net/http.rb:1580:in `do_start'
        from /usr/local/lib/ruby/3.3.0/net/http.rb:1569:in `start'
        from /usr/local/lib/ruby/3.3.0/net/http.rb:2297:in `request'
        from /usr/local/bundle/gems/httparty-0.22.0/lib/httparty/request.rb:156:in `perform'
        from /usr/local/bundle/gems/httparty-0.22.0/lib/httparty.rb:611:in `perform_request'
        from /usr/local/bundle/gems/httparty-0.22.0/lib/httparty.rb:521:in `get'
        from /usr/local/bundle/gems/httparty-0.22.0/lib/httparty.rb:644:in `get'
        from /srv/jekyll/_plugins/external-posts.rb:80:in `fetch_content_from_url'
        from /srv/jekyll/_plugins/external-posts.rb:62:in `block in fetch_from_urls'
        from /srv/jekyll/_plugins/external-posts.rb:60:in `each'
        from /srv/jekyll/_plugins/external-posts.rb:60:in `fetch_from_urls'
        from /srv/jekyll/_plugins/external-posts.rb:19:in `block in generate'
        from /srv/jekyll/_plugins/external-posts.rb:14:in `each'
        from /srv/jekyll/_plugins/external-posts.rb:14:in `generate'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/site.rb:193:in `block in generate'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/site.rb:191:in `each'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/site.rb:191:in `generate'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/site.rb:79:in `process'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/command.rb:28:in `process_site'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/commands/build.rb:65:in `build'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/commands/build.rb:36:in `process'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/command.rb:91:in `each'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
        from /usr/local/bundle/gems/jekyll-4.3.3/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
        from /usr/local/bundle/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
        from /usr/local/bundle/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
        from /usr/local/bundle/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
        from /usr/local/bundle/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
        from /usr/local/bundle/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
        from /usr/local/bundle/gems/jekyll-4.3.3/exe/jekyll:15:in `<top (required)>'
        from /usr/local/bundle/bin/jekyll:25:in `load'
        from /usr/local/bundle/bin/jekyll:25:in `<main>'

What operating system are you using?

Windows

Where are you seeing the problem on?

Running locally with Docker

More info

I use Microsoft Windows 10 Pro (10.0.19045 N/A Build 19045) as my main OS and Ubuntu 22.04.4 LTS as the Linux distribution for WSL 2.

@artyommatveev artyommatveev changed the title Can't access localhost on Windows while running docker on WSL2 Can't access localhost on Windows while running docker on WSL 2 Jul 12, 2024
@george-gca
Copy link
Collaborator

FYI you should paste your log between the 3 ticks (`). I believe your error is the same as in #2280.

@artyommatveev
Copy link
Author

artyommatveev commented Jul 12, 2024

@george-gca, thank you for the reply! I've tried to describe everything related to my problem thoroughly in this comment. In short, I've managed to solve the issue but still haven't found a solution that allows me not to disable the following rows in the _config.yml file:

external_sources:
  # - name: medium.com
  #   rss_url: https://medium.com/@al-folio/feed

@george-gca
Copy link
Collaborator

I'm afraid I can't help much further. When I used WSL 2, I used a local installation (not docker). My current setup is on Ubuntu.

@george-gca
Copy link
Collaborator

Are you using docker desktop? If so this might help.

@artyommatveev
Copy link
Author

@george-gca thanks for the recommendation! I'll look into it and get back with feedback. No, I've been using Docker Engine + Docker Compose.

@dermoth
Copy link

dermoth commented Jul 29, 2024

Are you using docker desktop? If so this might help.

FYI I was using this technique to launch X applications through VcXsrv long before Windows supported X natively and kept using it as Windows doesn't support the secondary clipboard and has issue with non-US keyboard mappings.

This technique stopped working recently - the IP from resolv.conf pings but it is no longer possible to connect to any port. I haven't found a solution for this yet. One workaround I tried was to add the external IP, i.e. the one Windows uses on the local network, but the connection often breaks killing applications at random times.

I use this only casually on some relative's PC as I personally use Linux only, therefore I can't tell when this broke exactly, but likely in the last 3-6 months (Windows 11, keeping updated but no preview/early versions).

@dermoth
Copy link

dermoth commented Jul 29, 2024

I actually fixed it, rather than taking the ip address from resolv.conf I get the default route:

$wslrt = wsl bash -c "ip -j route list default" | ConvertFrom-Json
$wslserv = $wslrt.gateway
C:\Windows\System32\wsl.exe ~ -- /usr/bin/env "DISPLAY=${wslserv}:0" /usr/bin/rxvt-unicode

The full script is slightly longer, it also gets WSL IP and adds it to allowed xhosts, and it's written as a oneliner...

@george-gca
Copy link
Collaborator

Can you provide more detailed information? This might help other users (and also users from other projects that might fall here from search).

@dermoth
Copy link

dermoth commented Aug 1, 2024

So the technique described in microsoft/WSL#1032 (I'm not sure if the comment anchor was on purpose, I was referring to the ticket itself) - using the DNS resolver's IP address to communicate with the host, i.e. this command from Linux:

remoteaddr=$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf)

In powershell it can be captured with:

$remoteaddr = wsl bash -c "awk '/nameserver/ {print \`$2; exit}' /etc/resolv.conf"

This worked for a while, but not anymore. WSL appears to have changed a bit the networking configuration and while this IP pings, it is no longer possible to use it to access other services.

Using the default gateway, OTOH, appears to work now (documented here although I specify the default route and prefer using json - you may have to install jq in your distro or use the command from the original documentation).

remoteaddr=$(ip -j route list default | jq -r '.[].gateway')

Or from Powershell (no need for jq):

$remoteaddr = (wsl bash -c "ip -j route list default" | ConvertFrom-Json).gateway

Alternatively, another way appears to be getting it directly from the HyperV Interface created for WSL - I can't remember where I found about this but the name has apparently changed from vEthernet (WSL) to vEthernet (WSL (Hyper-V firewall)), so I suspect this may related to the change that broke the original technique.

This should work regardless of the interface name, as long as there is only one marching the wildcard:

$remoteaddr = (Get-NetIPInterface "vEthernet (WSL*)" -AddressFamily IPv4 |Get-NetIPAddress).IPAddress

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

3 participants