将 WCF Windows 命名管道与 Docker 容器一起使用

Using WCF Windows Named Pipes with Docker Containers

我一直在尝试在本地连接到 docker 容器,该容器正在 运行 命名管道控制台应用程序。我无法通过 docker 容器从我的本地计算机连接到我的命名管道。我已经按照网上的片段进行操作,我发现通过在 docker 运行 中为命名管道声明音量来做到这一点,但我对如何让它工作感到困惑。下面是我正在使用的代码示例。

控制台应用程序入口点

        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

如有任何帮助,我们将不胜感激

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

[...] the netNamedPipeBinding binding, which provides cross-process communication on the same machine. Named pipes do not work across machines.

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

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