最近我一直在努力克服Docker在网络上的糟糕表现,而且一般来说,Docker会导致任何通过容器的通信延迟 .
我的情况是这样的:
我有3个容器相互通信,其中一个(“管理”容器)也通过端口绑定与外部通信,并公开一些服务用内容器做测试 . 对于内部 - 外部通信,我已经有了一个解决方案(即使我还在寻找更好的东西,使用桥接网络也很好),但我真正关心的是容器内通信 .
So here's the question: 使用this example provided by Microsoft我想尝试在windows主机下的linux docker容器中使用.net core中的命名管道 . 我'm using docker-compose so I assumed, at first, that adding the npipe as a volume would have done the trick but I'm有一些问题 .
使用此dockerfile:
version: '3.4'
services:
netcorepipetest.server:
image: netcorepipetestserver
build:
context: .
dockerfile: NetCorePipeTest.Server/Dockerfile
volumes:
- //./pipe/PipeName://./pipe/PipeName
netcorepipetest.client:
image: netcorepipetestclient
build:
context: .
dockerfile: NetCorePipeTest.Client/Dockerfile
volumes:
- //./pipe/PipeName://./pipe/PipeName
稍微修改源代码示例如下:
Server part
从:
NamedPipeServerStream pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);
至
NamedPipeServerStream pipeServer =
new NamedPipeServerStream(@"\\.\pipe\PipeName", PipeDirection.InOut, numThreads);
Client part
从
NamedPipeClientStream pipeClient =
new NamedPipeClientStream(".", "testpipe",
PipeDirection.InOut, PipeOptions.None,
TokenImpersonationLevel.Impersonation);
至
NamedPipeClientStream pipeClient =
new NamedPipeClientStream(@"\\.\pipe\PipeName");
我收到此错误:
Cannot create container for service netcorepipetest.client: b'Mount denied:\nThe source path "\\\\\\\\.\\\\pipe\\\\PipeName://./pipe/PipeName"\nis not a valid Windows path'
好吧,之后我搜索了一下只是为了让我更加困惑,当我偶然发现一个github问题(我真的不记得如何再次找到它),有人提到可能在编写中使用了长语法 - 文件会做的事情 . 更新compose文件后交换卷行:
volumes:
- type: tmpfs
#source: \\.\pipe\PipeName
target: \\.\pipe\PipeName
我不再在构建期间获得错误,但在执行阶段,不会发生任何应该发生的事情 . 服务器只是挂在那里什么都不做,客户端跟进 . 我究竟做错了什么?在Linux主机上更简单吗?
或者只是我的幻想使用自定义命名管道的可能性?
附: (我使用 tmpfs
作为类型,因为 bind
就像以前那样,它会出错)
Versions and tools:
-
Docker版本:用于Windows 18.03.1-ce的Docker
-
Linux容器
-
Host O.S . :Windows 10 Pro(64位)
-
.net-core版本:2.1
-
Visual Studio 2017作为IDE
如果您需要更多细节请不要害怕!