Search code examples
dockerhttpwindows-subsystem-for-linuxwebui

Accessing a Web service running on a WSL instance from outside the host computer


I have a perfectly functional system running Open WebUI, as follows:

  • Host system: Windows 11 with WSL running an Ubuntu 22.04.4 LTS
  • Ollama is installed within the WSL, using localhost:11434
  • Open WebUI: is installed inside a docker container within the WSL and it is accessible by the host system through the localhost:8080

I installed the docker container using:

$ docker run --runtime=nvidia -d --network=host --gpus all --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:cuda

I have no issues on accessing it in using my host system, but I'd like to know how could I access it from another computer in my network, from a browser just typing the fixed IP address of my machine like 192.168.x.x:8080.


Solution

  • I found a solution after doing some reading.

    The solution is for a Windows host, first I did a port forwarding using Powershell in Admin mode:

    netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=[WSL_IP]
    

    Just replace [WSL_IP] with your WSL instance IP.

    Then punch a hole in your Firewall to allow this port to be reached from outside:

    New-NetFirewallRule -DisplayName "Allow WSL2 Port" -Description "To allow Open WebUI through the firewall." -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8080
    

    Then it is done!