wslc networking: ports, DNS and user-defined networks
wslc networking (WSL2) is built on Windows HNS, the same Host Networking Service
that powers Windows containers. Containers get an IP behind a NAT virtual switch by default,
and published ports are mapped straight to Windows localhost with no extra proxy.
Publishing ports
The same -p / --publish flag you know from Docker works unchanged:
wslc run -d -p 8080:80 --name web nginx
This makes the container reachable at http://localhost:8080. TCP and UDP are
both supported (-p 53:53/udp). The published port is also reachable from other
machines on the LAN when the Windows Firewall allows it — no Docker Desktop port-forwarding
quirks.
User-defined networks
Create a network, then attach containers to it. Container names become DNS names:
wslc network create mynet
# start a database
wslc run -d --network mynet --name db -e POSTGRES_PASSWORD=secret postgres:16-alpine
# start an app that reaches the database by DNS name "db"
wslc run -d --network mynet --name app -p 3000:3000 myapp
Containers on different networks are isolated by default. You can connect a running
container to additional networks with wslc network connect mynet app2.
What does not work
--network host— rejected with exit 1.- Overlay / multi-host networking — not available in the preview.
- Macvlan / IPvlan — not documented in 2.9.4.0.
- Docker Compose network aliases — wslc has no compose runtime.
Network management commands
| Task | Command |
|---|---|
| List networks | wslc network ls |
| Create a network | wslc network create <name> |
| Remove a network | wslc network rm <name> |
| Connect a container | wslc network connect <net> <container> |
| Disconnect a container | wslc network disconnect <net> <container> |
| Inspect a network | wslc network inspect <name> |
DNS and hostname
wslc supports --dns, --dns-option, --dns-search,
--hostname and --domainname. Container names on user-defined
networks resolve via the built-in DNS, so --name db means the app container
can reach it at hostname db.
Comparing network models
| Feature | wslc 2.9.4 | Docker Desktop |
|---|---|---|
| Published ports on localhost | Yes | Yes |
| User-defined bridge networks | Yes | Yes |
| Container-name DNS | Yes | Yes |
| Host networking | No | Yes |
| Overlay / multi-host | No | Yes (Swarm) |
| Macvlan | No | Yes |