【发布时间】:2020-11-30 22:37:30
【问题描述】:
我一直在尝试连接到本地运行命名管道控制台应用程序的 docker 容器。我无法通过 docker 容器从本地计算机连接到我的命名管道。我已经在线跟踪了 sn-ps,我发现通过在命名管道的 docker run 中声明卷来做到这一点,但我对如何让它工作感到有些困惑。下面是我正在使用的代码示例。
控制台应用程序入口点
private static void Main(string[] args)
{
using (var host = new ServiceHost(new DiscoveryProxyService(), "net.pipe://localhost/testname"))
{
ServiceDiscoveryProxyEndpointConfigurator.Configure(host, endpointConfig);
host.Open();
}
}
我的 Docker 文件看起来像这样
FROM mcr.microsoft.com/dotnet/framework/wcf:4.7.2-windowsservercore-ltsc2019
SHELL ["powershell"]
RUN Install-WindowsFeature -name NET-WCF-Pipe-Activation45
RUN Install-WindowsFeature -name NET-WCF-TCP-Activation45
RUN Install-WindowsFeature -name NET-WCF-HTTP-Activation45
# Next, this Dockerfile creates a directory for your application
WORKDIR WcfDiscoveryProxyTest
# Copies the site you published earlier into the container.
COPY WcfDiscoveryProxyTest/ .
# start WCFTCPSElfHost service process in container as entrypoint process.
ENTRYPOINT .\bin\Debug\WcfDiscoveryProxyTest.exe
我的 Docker 命令如下
docker build -t test:latest .
docker run -d -itd -v \\.\pipe\localhost\testname:\\.\pipe\localhost\testname test:latest
任何帮助将不胜感激
【问题讨论】:
-
代码是否在 docker 之外按预期工作?意思是,您确定问题出在 docker 配置上吗?
-
@CoolBots 是的。如果我在本地运行服务,我可以成功连接。这是通过 Visual Studio 调试器运行的。
-
您是否尝试将 localhost 替换为配置中的完整机器名称?
-
要记住的一点是,对于在容器中运行的应用程序,
localhost是容器,而不是您的本地机器。如果你在那里使用localhost,它将寻找在容器中运行的其他东西。考虑使用可以管理网络连接的工具,例如 Docker Compose 或 Docker 内置的 Kubernetes,以允许与容器的连接正常工作。我有一个类似的问题:stackoverflow.com/questions/59461691/…
标签: c# docker wcf named-pipes