即使在.net核心控制台应用程序中使用Console.ReadLine(),Docker容器也会立即退出 [英] docker container exits immediately even with Console.ReadLine() in a .net core console application
问题描述
我试图在Docker容器内运行一个.net核心1.0.0控制台应用程序。
当我从里面运行 dotnet run
命令我的机器上的Demo文件夹,它工作正常;但是当使用 docker run -d -name demo Demo
运行时,容器立即退出。
I am trying to run a .net core 1.0.0 console application inside a docker container.
When I run dotnet run
command from inside the Demo folder on my machine, it works fine; But when run using docker run -d --name demo Demo
, the container exits immediately.
我尝试了 docker日志演示
来检查日志,它只显示Console.WriteLine中的文本: / p>
I tried docker logs demo
to check the logs and it just shows the text from the Console.WriteLine:
演示应用程序运行...
Demo app running...
没有其他的。
我已经通过 https ://github.com/learningdockerandnetcore/Demo
该项目包含 Programs.cs
, Dockerfile
用于创建演示图像,以及 project.json
文件。
The project contains Programs.cs
, Dockerfile
used to create Demo image, and project.json
file.
推荐答案
您应该以守护程序模式运行容器(使用 -i
选项)。但请注意,运行容器时,后台进程将立即关闭,以确保您的脚本在前台运行,否则将无法正常工作。
You should either run your container in the daemon mode (with -i
option). but please note that the background processes will be closed immediately when you run the container so make sure your script is run in the foreground or it simply won't work.
这篇关于即使在.net核心控制台应用程序中使用Console.ReadLine(),Docker容器也会立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!