Two WSL2 + Docker Networking Pitfalls: Silently Occupied Ports & Host Mode localhost Unreachable
· 5 min read
TL;DR
Two common networking pitfalls with WSL2 + Docker Desktop:
- Silently occupied port: When a Docker container maps 5432, SSH tunnel
localhost:5432connects to the container's PostgreSQL instead of the remote server — the password is correct, but you're hitting the wrong instance - Host mode localhost unreachable:
network_mode: hostshares the Docker utility VM's network, not WSL2's —curl localhost:8080fails