Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To reach a Linux container from Windows, publish its port with Docker, then connect to the published host port—usually through localhost. WSL, Docker Desktop’s Linux VM, and the container are separate networking contexts, so the right address depends on which machine initiates the connection.

Which machine is connecting to which?

Think of the connection as crossing distinct layers: Windows host, a WSL 2 distribution, Docker Desktop’s Linux VM, and the container. A service running directly in WSL is not the same as one running in a container, and Docker’s published-port mapping is not the same as WSL’s localhost forwarding.

Connection direction Address or mechanism What it does
Windows → service in WSL localhost:<port> by default with WSL 2 NAT WSL localhost forwarding lets Windows reach a service running in the distribution.
WSL → service on Windows Windows host IP from the WSL default route under NAT Connects from Linux to a Windows-hosted service; this is the reverse direction, not localhost forwarding.
Windows → container in Docker Desktop Published host port, such as localhost:8080 Docker Desktop’s backend forwards the connection through its Linux VM to the container port.
Container → service on Docker Desktop host host.docker.internal Resolves the Docker Desktop host from within the container.

How to reach a service running directly in WSL

With WSL 2’s default NAT networking, start the service in your Linux distribution and connect from Windows to http://localhost:<port>. For example, if the service listens on port 3000, open http://localhost:3000. WSL localhost forwarding is enabled by default in the documented configuration.

If Windows cannot connect, first verify that the service is running and listening on the intended port and interface. Then check whether localhost forwarding has been disabled in the WSL configuration. In .wslconfig, the localhostForwarding setting controls whether WSL VM ports bound to wildcard or localhost addresses can be reached from Windows using localhost.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

To find a WSL distribution’s IP from Windows, run:

wsl.exe --distribution <DistroName> hostname -I

This reports the distribution’s address. It is not the Windows host IP that Linux needs when a process inside WSL connects to a Windows service.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How a WSL process connects to a Windows service

Under NAT, a Linux process in WSL should connect to the Windows host IP. From the distribution, obtain the address from the default route with:

ip route show | grep -i default | awk '{ print $3}'

Use the resulting address with the Windows service’s listening port. This path is different from Windows connecting to WSL through localhost.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

How to publish a Docker container port to Windows

Docker’s -p option maps a host port to a port inside the container. The format is HOST_PORT:CONTAINER_PORT. For example:

docker run --rm -p 127.0.0.1:8080:80 nginx

This maps host loopback port 8080 to container port 80. Open http://localhost:8080 from Windows. The application in the container must actually listen on port 80 for this mapping to work; the host and container port numbers do not have to match.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The host-side binding controls where the published port can be reached. Without a host IP, Docker publishes on all host interfaces by default. An explicit 127.0.0.1 binding limits access to the host’s loopback interface; a broader binding may allow other machines to connect depending on the network and firewall rules.

Published, exposed, and random ports

Option Effect Host port
EXPOSE or --expose Declares or exposes a container port; by itself it does not publish that port to the host. No host mapping created.
-p HOST_PORT:CONTAINER_PORT Publishes a specific host-to-container port mapping. Chosen explicitly.
-P Publishes ports marked exposed. Selected randomly; inspect the mapping with docker port.

Docker Desktop’s backend accepts connections to published host ports and forwards them through its Linux VM to the container. Publishing is the step that makes a container’s listening port reachable from Windows; merely declaring an exposed port is not enough.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How a container connects to a service on Windows

From a Docker Desktop container, use host.docker.internal as the hostname for a service running on the Docker Desktop host. This is for container-to-host connections. It does not publish a port for Windows to connect to a service in the container; use -p for that direction.

Choosing between WSL NAT and mirrored networking

NAT is WSL’s default. Microsoft documents mirrored networking for Windows 11 version 22H2 and later. It adds networking capabilities and can improve compatibility for some setups, but the connection behavior and firewall considerations differ.

Consideration NAT Mirrored
Windows ↔ WSL localhost Windows can generally reach a WSL service through localhost using forwarding. For WSL-to-Windows, use the Windows host IP from the default route. For the documented Windows/WSL localhost path, use IPv4 127.0.0.1; ::1 is not supported for that path.
Eligibility Default WSL 2 networking mode. Requires Windows 11 version 22H2 or later.
Networking needs Does not provide the mirrored-mode benefits listed by Microsoft. Documented benefits include IPv6 support, improved VPN compatibility, multicast, and direct LAN access to WSL.
Inbound LAN access Depends on network configuration and firewall policy. Still depends on firewall policy; Microsoft documents Hyper-V firewall configuration examples.
Docker Desktop port publishing No mirrored-mode-specific published-port issue noted here. Microsoft documents a known published-port failure under the default namespace; consult its current WSL troubleshooting guidance before applying a workaround.

WSL’s configuration reference lists networkingMode values including nat, mirrored, none, deprecated bridged, and virtioproxy. NAT is the default. Choose mirrored mode for its documented networking features when the Windows version qualifies, but account for firewall rules and the Docker Desktop issue described above.

Troubleshoot a port that will not open

  1. Locate the service. Establish whether it runs directly in a WSL distribution or inside a Docker container. The WSL guest, Docker Desktop VM, and container are distinct network contexts.
  2. Check that it is listening. Confirm the application is running on the expected port and bound to an interface that can accept the forwarded connection.
  3. Check the container mapping. Inspect the docker run options or Compose port mapping. EXPOSE alone does not publish a host port; use a published mapping such as -p 8080:80.
  4. Match the address to the connection direction. Windows-to-container uses the published host port; a container reaching the Docker Desktop host uses host.docker.internal; under NAT, WSL reaching Windows uses the host IP from the default route.
  5. Verify the bind address and port pair. The container-side port must match the port on which the application listens. The host-side port can differ. A host binding of 127.0.0.1 restricts a published port to host loopback, while an unspecified host IP binds all interfaces by default.
  6. Review firewall policy. Windows Firewall or Hyper-V firewall rules can block inbound connections, particularly when reaching a service from another machine. Mirrored-mode WSL LAN access may require an appropriate Hyper-V firewall rule.
  7. For mirrored-mode Docker failures, verify the current known issue. Microsoft documents a Docker Desktop published-port failure when mirrored mode uses the default namespace. Listed workarounds include --network host or configuring the port under experimental ignoredPorts. Host networking changes the container’s network isolation and port-publishing behavior, so it is not an equivalent drop-in replacement for ordinary port publishing.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.