- Using the wslc.exe tool to manage Linux containers natively on Windows 11 without relying on external licenses.
- Implementing port mapping using the -p parameter to make services accessible via localhost.
- Advanced network configuration and DNS tunneling to avoid conflicts with corporate VPNs and firewalls.
How to expose the port of a WSL container in Windows 11? If you've upgraded to Windows 11 and want to get into containers without the hassle of expensive licenses or cumbersome installations, you've come to the right place. Managing isolated environments used to be a headache, but thanks to Microsoft integrating container support directly into the system, it's much easier. Windows Subsystem for Linux (WSL)Now we can deploy applications natively and in a lightweight way.
The big news is the arrival of a tool called wslc.exeThis essentially allows us to stop relying solely on Docker Desktop. Whether you're looking to set up a web server for a quick test or deploy a more robust infrastructure, understanding how to expose ports and configure the network is key to making your services accessible from a Windows browser.
What exactly is WSL Containers and how does it differ from Docker?
To begin, it must be made clear that WSL Containers is not an invention that comes to replace the concept of a container, but a way of manage Hyper-V micro-VMs dedicated resources for each instance. Unlike the traditional model where all containers share a single Linux virtual machine, here each workload has its own resource budget and isolation, which implies a A significant leap forward in security and efficiency.
If we compare this to Docker Desktop, the most noticeable difference is the cost. While Docker requires subscriptions for large enterprises, WSL containers come with a subscription fee. included for free in Windows 11Furthermore, file input and output performance has improved significantly thanks to the implementation of virtiofs, eliminating those annoying bottlenecks we used to experience when mounting volumes between Windows and Linux.

Step-by-step guide to installing and setting up wslc
Before you start exposing ports, you need to make sure your system is properly configured. Not just any version will work, as this feature is still in preview. To begin, open a terminal as administrator and run wsl --update --pre-releaseIt is essential that you have Hyper-V enabled in your BIOS or UEFI, since it is the engine that allows container isolation.
Once the kernel has been updated, the next step is to install the specific feature by running the command wsl --install-feature containersTo check that everything is working perfectly, simply write wslc versionIf you see the build string, you can now start downloading images from OCI-compatible registries, such as Docker Hub, using the command wslc pull ubuntu:24.04 For example.

How to expose a container port in Windows 11
This is where the magic happens. To make an application running on Linux visible on your Windows system, you need to perform a port mapping at the time of launching the container. The key parameter is -p, followed by the Windows port and the container port.
Imagine you want to start an Nginx server. The command would be: wslc run -d -p 8080:80 --name mi-web nginxIn this case, we are saying that all traffic arriving at the port 8080 of your localhost be redirected to port 80 of the container. Once this is done, simply open your browser and go to http://localhost:8080 to see your server running without having to configure complex manual network rules.

Custom image creation and deployment
If pre-made images aren't enough for you, you can create your own. Containerfile (which is virtually identical to a Dockerfile). For example, for a Django app, you would define the base Python image, copy the requirements, and use the instruction EXPOSE 8000 to indicate which port the application uses internally.
To convert that file into a real image, you use wslc build -t mi-app-django .Then, when you run it, you apply the same port principle: wslc run -d -p 8000:8000 mi-app-django. If you use Visual Studio CodeYou can make your life much easier by installing the WSL extension and changing the Docker Path to wslc, allowing you to debug the code directly in the container.

Problem-solving and complex networks
It's not all smooth sailing. Sometimes you'll encounter the error that a port is already in use. This is very common with port 53 (DNS), where internal Windows services can conflict. If this happens to you, check that you don't have other ports in use. active network services or try changing the external port of the mapping.
Another critical point is connectivity when using a VPN. If you notice you're losing internet access within WSL, you may need to enable it. DNS tunneling in the file .wslconfigEstablishing dnsTunneling=true In the experimental section, you prevent the company's network policies from blocking DNS queries from the virtual machine.
Other tools and final considerations
If you're coming from Docker Desktop and don't want to delete it, that's fine. You can have both systems coexisting on the same machine without conflicting, since they use different runtime environments. However, remember that for full integration and to see the WSL containers in the Docker Desktop interface, you must enable the specific integration of the distribution in the Docker Resources settings.
For those working with Artificial Intelligence, the good news is that wslc supports accessing the graphics card via the flag --gpus allwhich allows models of PyTorch or TensorFlow They fly by leveraging the power of Windows hardware. However, keep in mind that this technology requires Windows 11 Pro, Enterprise or Educationbecause the Home version does not support the necessary Hyper-V isolation.
Having complete control over Linux containers directly from the Windows 11 kernel greatly simplifies the workflow, allowing us to seamlessly transition from creating images with wslc to accessing them via localhost. While still in preview and some features like Docker Compose are evolving, the ability to map ports and manage networks natively makes it a powerful and free alternative for any developer.
Passionate about technology since he was little. I love being up to date in the sector and, above all, communicating it. That is why I have been dedicated to communication on technology and video game websites for many years. You can find me writing about Android, Windows, MacOS, iOS, Nintendo or any other related topic that comes to mind.