【问题标题】:Using WCF Windows Named Pipes with Docker Containers将 WCF Windows 命名管道与 Docker 容器一起使用
【发布时间】: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


【解决方案1】:

恐怕你运气不好。 WCF 仅在同一台机器上支持命名管道...

[...] netNamedPipeBinding 绑定,它在同一台机器上提供跨进程通信。命名管道不能跨机器工作。

https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/netnamedpipebinding

这将(很可能)也适用于 docker 容器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 2021-04-09
    • 2014-09-24
    • 2019-08-17
    • 2011-03-05
    • 1970-01-01
    • 2011-07-04
    相关资源
    最近更新 更多