Docker Community Forums

Share and learn in the Docker community.

Access WSL2 Docker container using public IP

I have Docker Container which I am able to access within my machine using localhost.
I have this docker container for production test and want to give other people access to this docker container using the Domain name. hosting temp on local PC will help me to save some cost . Any help how i can access this using public IP

Host Name:                 CORE
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22000 N/A Build 22000
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          ***********
Registered Organization:
Product ID:                00330-80123-50100-AA723
Original Install Date:     7/2/2021, 9:46:06 AM
System Boot Time:          12/27/2021, 6:51:25 PM
System Manufacturer:       ASUS
System Model:              System Product Name
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: AMD64 Family 23 Model 113 Stepping 0 AuthenticAMD ~3800 Mhz
BIOS Version:              American Megatrends Inc. 4007, 12/9/2020
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume3
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
Total Physical Memory:     32,664 MB
Available Physical Memory: 15,627 MB
Virtual Memory: Max Size:  37,824 MB
Virtual Memory: Available: 12,508 MB
Virtual Memory: In Use:    25,316 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              \\CORE
Hotfix(s):                 5 Hotfix(s) Installed.
                           [01]: KB5007292
                           [02]: KB5004567
                           [03]: KB5008295
                           [04]: KB5008215
                           [05]: KB5007414
Network Card(s):           3 NIC(s) Installed.
                           [01]: TAP-NordVPN Windows Adapter V9
                                 Connection Name: Ethernet 2
                                 Status:          Media disconnected
                           [02]: Intel(R) I211 Gigabit Network Connection
                                 Connection Name: Ethernet
                                 DHCP Enabled:    Yes
                                 DHCP Server:     192.168.1.1
                                 IP address(es)
                                 [01]: 192.168.1.4
                                 [02]: fe80::8578:8059:93d4:1ec4
                           [03]: Bluetooth Device (Personal Area Network)
                                 Connection Name: Bluetooth Network Connection
                                 Status:          Media disconnected
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

I’ve asked this question twice here and have never received an answer, so good luck!

Something about the vm / hypervisor does not allow external connections. Apparently this is also true for Mac. There are some complex workarounds but they are container specific.

I have only found two solutions that work:

  1. Use a forwarding service like ngrok or localtunnel to temporarily share the access from localhost.

  2. Bring up the container on a Linux boot. Docker on Linux has none of the limitations that Windows has.

Without @johnsimmonshypertext’s response I would have no clue what the original post is about.

A public ip usualy refers to an internet ip, though the OP probably meant the host’s private ip.

So the problem seem to be that the default behavior of WSL2, which binds a port from a wsl2 distribution to localhost on the host, does not bind it to the host private ip as well.

This indeed is how WSL2 works and there is a workaround for this: [WSL 2] NIC Bridge mode 🖧 (Has TCP Workaround🔨) · Issue #4150 · microsoft/WSL · GitHub

Though, this is not a docker issue. It is an issue of the platform docker is used on.

The suggestions of @johnsimmonshypertext are the ways to go forward.

You are aware this is a forum from users for users, aren’t you? So your contribution is exactly what makes the forum move. There is rarely an “official” answer: most responses are based on experiences and sometimes just a better understanding of the documentation or beeing more skilled in google-fu

Thank you for your response! Since almost anyone has more experience than me, I had hoped for a simple answer to what I thought was a simple question. I did contribute what I knew, but your google-fu far outshone! I’m going to try the WSL workaround later as well.

I am not sure my answer is any better than your:

  • your ngrok suggestion does cover public access using a public domain name
  • what I found does only cover lan access using local host names

It realy depends on the use case - I am still not sure which one of both the OP had in mind.

But that is what localtunnel or ngrok does by default. It creates a tunnel from sub host name.ngrok.io to the web app container on local host:port.