Reputation: 156
I got a MongoDB instance running inside a container inside WSL2.
When I try to do a request in my browser at localhost:27017
it works even if it's display an error because I try to access to the db with a HTTP protocol.
But when I'm trying to access to my db from Compass with hostname localhost and port 27017, I got a timeout after 30000ms and I can't access to it.
Someone got an idea why, please ?
Upvotes: 5
Views: 3856
Reputation: 154
I was able to connect mongoDB instance only using WSL2 IP address.
You can get it by running this one inside WSL:
ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1
or this one in powershell on windows host:
[Regex]::Match((wsl -- ip addr show eth0), 'inet (?<IP>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/').Groups["IP"].Value
Bad news: this IP changes on every WSL2 restart. There is a go-wsl2-host that adds a host for this IP and keeps it updated. But I never used it.
Upvotes: 3