.NET project not able to connect to Docker container in WSL2 via localhost from the host OS

  .net-5, docker, windows, wsl-2

I am not using Docker Desktop, I only installed the CLI on Ubuntu, on WSL2. I also downloaded RabbitMQ image and successfully connected to localhost:15672 from my browser on Windows host.

But, when it came to the .NET project, it wasn’t possible. This is the connection string:

"host=localhost:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!"

One solution was to use eth0’s inet IP address from within Ubuntu, but I have many projects using this connection, it is a pain to modify it every day, at least.

"host=123.45.67.890:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!"

Why is that I am able to connect to the container via browser but not form the .NET project and how could I manage to do it?

Source: Windows Questions

LEAVE A COMMENT