问题描述
我正在尝试在 docker 容器内运行 .NET Core 1.0.0 控制台应用程序.
当我从机器上的 Demo 文件夹中运行 dotnet run
命令时,它工作正常;但是当使用 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 logs demo
来检查日志,它只显示来自 Console.WriteLine 的文本:
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
用于创建Demo镜像,project.json
文件.
The project contains Programs.cs
, Dockerfile
used to create Demo image, and project.json
file.
推荐答案
您应该在交互模式下运行您的容器(使用 -i
选项),但请注意后台进程将被关闭当您运行容器时立即运行,因此请确保您的脚本在前台运行,否则它根本无法工作.
You should run your container in Interactive mode (with the -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 Core 控制台应用程序中使用 Console.ReadLine(),docker 容器也会立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!