[英].NET project not able to connect to Docker container in WSL2 via localhost from the host OS
I am not using Docker Desktop, I only installed the CLI on Ubuntu, on WSL2.我没有使用 Docker 桌面,我只在 WSL2 上的 Ubuntu 上安装了 CLI。 I also downloaded RabbitMQ image and successfully connected to localhost:15672 from my browser on Windows host.
我还下载了 RabbitMQ 图像并从 Windows 主机上的浏览器成功连接到 localhost:15672。
But, when it came to the .NET project, it wasn't possible.但是,当涉及到 .NET 项目时,这是不可能的。 This is the connection string:
这是连接字符串:
"host=localhost:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!"
“主机=本地主机:5672;publisherConfirms=true;超时=25;用户名=nerdstore;密码=!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.一种解决方案是从 Ubuntu 中使用 eth0 的 inet IP 地址,但我有很多项目使用此连接,至少每天都修改它很痛苦。
"host=123.45.67.890:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!"
“主机=123.45.67.890:5672;publisherConfirms=true;超时=25;用户名=nerdstore;密码=!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?为什么我能够通过浏览器连接到容器但不能形成 .NET 项目,我该如何做到这一点?
Add your Ubuntu IP 123.45.67.890
into hosts file with your custom hostname wsl2.ubuntu
by below command.使用您的自定义主机名
wsl2.ubuntu
将您的 Ubuntu IP 123.45.67.890
添加到 hosts 文件中
Make sure you run PowerShell as administrator.确保以管理员身份运行 PowerShell。
Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`n123.45.67.890`twsl2.ubuntu" -Force
Then you connection would be like this然后你的连接会是这样的
"host=wsl2.ubuntu:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!"
“主机=wsl2.ubuntu:5672;publisherConfirms=true;timeout=25;username=nerdstore;password=!abcd1234!”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.