WSL2 Mirrored Network Mode: Compatibility Overview & Dev Projects
This article provides an overview of the WSL2 (Windows Subsystem for Linux version 2) mirrored network mode and explores compatible development projects. Specifically, we will focus on utilizing WSL2 without Docker containers. The content includes key concepts, subtitles, paragraphs, code blocks, and references to help you better understand and apply this technology in your dev projects.
Understanding WSL2 and Mirrored Network Mode
WSL2 is a significant upgrade from WSL that allows developers to run a full Linux environment on Windows. The mirrored network mode in WSL2 enables better networking functionality for applications running inside the WSL2 environment. By default, WSL2 uses a NAT networking stack, but the mirrored network mode allows it to use the Windows host's network stack instead. This functionality is particularly useful for developers working on projects that require better network functionality and seamless interaction between Windows and Linux environments. Learn more about WSL2 and its features in the official documentation.
Dev Projects Using WSL2 Mirrored Network Mode
The following projects and examples demonstrate how to leverage WSL2's mirrored network mode without Docker containers. For each project, we will provide an introduction, setup instructions, and sample code.
Project 1: LAMP Stack Development
The LAMP (Linux, Apache, MySQL, PHP) stack is a popular development environment for web applications. With WSL2, you can set up a LAMP stack easily on your Windows system. By using the mirrored network mode, you ensure seamless networking with your Windows environment.
# Power off Docker if it's running
ddev poweroff
# Create a new directory for your test project
mkdir ~/tmp/testddev
# Navigate to the new directory
cd ~/tmp/testddev
# Set up the LAMP stack using Docker (under WSL2)
wsl -d Ubuntu -u root -e "sudo apt update && sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql"
Project 2: Node.js Development
Node.js is a JavaScript runtime that can run on various platforms, including Windows and Linux. With WSL2, you can create a Node.js project and utilize the mirrored network mode for improved network functionality.
# Power off Docker if it's running
ddev poweroff
# Create a new directory for your test project
mkdir ~/tmp/testnode
# Navigate to the new directory
cd ~/tmp/testnode
# Set up Node.js and Express using npm
npm init -y
npm install express --save
# Create a server.js file with the following content:
echo 'const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello, World!");
});
app.listen(3000, () => {
console.log("Example app listening on port 3000!");
});' > server.js
# Start the Node.js server
node server.jsReferences
- Book: Windows Subsystem for Linux: The Developer's Guide by Michael Levan, Chris Tuleski, and Kevin Tucker
- Article: "Running Docker Containers in WSL2 Without the Linux Docker Desktop Daemon"
- Online Resource: "WSL 2 Networking" - Official Microsoft Documentation