Search code examples
c#dockerwcfnamed-pipes

Using WCF Windows Named Pipes with Docker Containers


I have been attempting to connect to a docker container locally which is running a named pipe console application. I cannot connect to my named pipe from my local computer via the docker container. I have followed the snippets online I have found to do this by declaring the volume in the docker run for the named pipe, but I am kind of stumped on how to get this to work. Below is an example of the code I am using.

Console Application Entry Point

        private static void Main(string[] args)
        {
                using (var host = new ServiceHost(new DiscoveryProxyService(), "net.pipe://localhost/testname"))
            {
                ServiceDiscoveryProxyEndpointConfigurator.Configure(host, endpointConfig);
                host.Open();
            }
         }

My Docker File looks like this

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

My Docker commands are the following

docker build -t test:latest .
docker run -d -itd -v \\.\pipe\localhost\testname:\\.\pipe\localhost\testname test:latest

Any help would be greatly appreciated


Solution

  • I'm afraid, you're out of luck. WCF supports named pipes only on the same machine...

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

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

    This will (most likely) also apply to docker containers.