使用时,我注意到了奇怪的行为docker-compose
。Console.ReadLine()
不等待用户输入。
观察以下简化的点网核心c#控制台应用程序:
private static void Main(string[] args)
{
Console.WriteLine("Input something:");
while (true)
{
var line = Console.ReadLine();
Console.WriteLine($"{DateTime.Now} Input was: {line}");
System.Threading.Thread.Sleep(1000);
}
}
如果您通过docker run -i readline
它运行它可以正常工作:
但是,如果使用docker-compose up
它,则仅循环而无需等待STDIN上的输入:
这是为什么?
您可以使用以下方法自己尝试:
git clone https://github.com/mh-qUjB/docker-dotnetcore-readline.git
cd ./docker-dotnetcore-readline/ReadLine
docker-compose up
我目前正在对此进行测试:
Ubuntu 16.04
Docker version 18.06.1-ce, build e68fc7a
docker-compose version 1.22.0, build f46880fe
<TargetFramework>netcoreapp2.1</TargetFramework>
谢谢。
PS:如果您可以改善此问题的标题,我将很高兴。
您可以找到单个容器并在该容器中执行命令。Docker compose正在流式传输日志,因此,它不为您提供交互式外壳。
例如,假设您有此撰写文件,
version: '3'
services:
nats:
image: nats-streaming
mongo:
image: mongo
您可以像下面这样在每个容器中执行命令
docker-compose exec mongo sh
docker-compose exec nats sh
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句