Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

WSL Mirrored Mode Networking in Docker Desktop 4.26: Improved Communication and Development Workflow

2 min read

Docker Desktop 4.26.0 added support for WSL mirrored mode networking! This is a significant improvement for developers who use WSL (Windows Subsystem for Linux) alongside Docker Desktop, as it allows them to share network resources between their WSL distribution and their Docker containers. This can be helpful for a variety of purposes, such as developing and testing web applications that need to communicate with both Linux and Windows systems.

Here are some additional details about WSL mirrored mode networking in Docker Desktop 4.26.0:

  • It requires WSL version 2.0.4 or later.
  • It can be enabled in the Docker Desktop settings.
  • Once enabled, Docker will automatically create a virtual network that is shared between your WSL distribution and your Docker containers.
  • You can then configure your WSL applications and Docker containers to use this shared network.

WSL mirrored mode networking is a welcome addition to Docker Desktop 4.26.0 and should make it easier for developers to work with both WSL and Docker containers.

What is WSL Mirrored Mode Networking?

WSL mirrored mode networking is a new networking architecture introduced in WSL 2. It essentially bridges the gap between your Windows host and your WSL distribution by “mirroring” the network interfaces available on your Windows machine into the Linux environment. This creates a shared network space where both WSL applications and Docker containers can reside and communicate freely.

Why is it useful?

In the traditional NAT-based network setup, WSL applications and Docker containers are isolated from each other in separate virtual networks from the Windows host. This made communication between them a bit convoluted, requiring complex port forwarding configurations. For instance, to access a Docker container from a WSL application, you’d need to create a port forwarding rule between a port on the WSL application and a port on the Docker container.

With mirrored networking mode, both WSL applications and Docker containers directly connect to the physical network of the Windows host. This allows them to communicate directly with each other, eliminating the need for complex port forwarding configurations.

Here are some specific benefits of using WSL mirrored mode networking:

  • Improved compatibility: This mode resolves various compatibility issues faced with VPNs, multicast applications, and IPv6 support in the older NAT-based networking.
  • Simplified communication: Both WSL applications and Docker containers can directly access each other and other network resources on the host machine, eliminating the need for complex port forwarding configurations.
  • Enhanced development workflow: Developers can easily test and debug web applications or microservices that span across both Linux and Windows environments.
  • Direct LAN access: WSL applications can now directly connect to other devices on your local network, opening up new possibilities for network-aware applications.

How to enable it?

To enable WSL mirrored mode networking, you need to:

  • Ensure you have WSL 2 version 2.0.4 or later: Check your WSL version by running wsl -l in a PowerShell terminal. Edit the .wslconfig file: This file contains configuration settings for your WSL distribution. You can find it in the %AppData%\Microsoft\Windows\WSL directory. Open the file with a text editor and add the following line under the [wsl2] section:
networkingMode=mirrored
  • Restart your WSL distribution: Run wsl –shutdown in a PowerShell terminal to gracefully shut down your WSL distribution. Then, simply restart it using the usual methods.

Demo

Here’s an example with multiple containers to demonstrate how WSL mirrored mode networking simplifies communication and eliminates port forwarding:

Scenario:

You’re building a microservices architecture with three services:

  • A frontend web app (Container 1)
  • A backend API (Container 2)
  • A database (Container 3)

Without Mirrored Mode:

Start containers with port mappings:
Bash

docker run -p 8080:80 frontend-app
docker run -p 5000:5000 backend-api
docker run -p 3306:3306 database

With Mirrored Mode:

Start containers without port mappings:

docker run frontend-app
docker run backend-api
docker run database

Key Benefits:

  • No port conflicts: Eliminates the need to manage port mappings, reducing configuration complexity.
  • Isolated networks for containers: Each container has its own – IP address within the shared network, promoting better isolation and security.
  • Direct communication: Containers can communicate directly using hostnames or IP addresses, simplifying service discovery and interaction.
  • Easier multi-container testing: Simplifies testing and debugging of complex systems with multiple containers, reducing setup overhead.

Please Note:

  • WSL mirrored mode networking is still under development, and you might encounter some bugs or limitations.This mode can potentially expose your WSL applications to a wider network surface, so be mindful of security considerations.
  • Some applications might require additional configuration to work properly with the shared network space.

WSL mirrored mode networking is a promising advancement that simplifies development workflows and unlocks new possibilities for working with WSL and Docker containers. If you’re a developer who frequently juggles between Linux and Windows environments, it’s definitely worth exploring!

Keep Reading

Please follow and like us:

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

This website uses cookies. By continuing to use this site, you accept our use of cookies. 

Join our Discord Server