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.
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.
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.
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 -lin a PowerShell terminal. Edit the
.wslconfigfile: This file contains configuration settings for your WSL distribution. You can find it in the
%AppData%\Microsoft\Windows\WSLdirectory. Open the file with a text editor and add the following line under the
- 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.
Here’s an example with multiple containers to demonstrate how WSL mirrored mode networking simplifies communication and eliminates port forwarding:
You’re building a microservices architecture with three services:
- A frontend web app (Container 1)
- A backend API (Container 2)
- A database (Container 3)
Start containers with port mappings:
docker run -p 8080:80 frontend-app
docker run -p 5000:5000 backend-api
docker run -p 3306:3306 database
- Access frontend: http://localhost:8080 API calls:
- Frontend calls backend: http://localhost:5000/api
- Backend calls database: http://localhost:3306
Start containers without port mappings:
docker run frontend-app
docker run backend-api
docker run database
- Access frontend: http://localhost:8080 (directly accessible) API calls:
- Frontend calls backend: http://backend-api:80 (using container hostname)
- Backend calls database: http://database:3306 (using container hostname)
- 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.
- 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!
Unlock the potential of Ollama, an open-source LLM, for text generation, code completion, translation, and more. See how Ollama works and get started with Ollama WebUI in just two minutes without pod installations! #LLM #Ollama #textgeneration #codecompletion #translation #OllamaWebUI
Discover how to effectively leverage the potential of Ollama within your development workflow using Docker Desktop and Kubernetes for seamless containerization and orchestration. #Ollama #DockerDesktop #Kubernetes #DevelopmentWorkflow
SonarQube is a powerful tool for continuous code quality inspection, helping developers enhance code quality by identifying bugs, code smells, security vulnerabilities, and more. Learn how the integration with Docker Scout ensures quality gates are met for your Docker images. #codequality #SonarQube #DockerScout #integration