即使在 .NET Core 控制台应用程序中使用 Console.ReadLine() docker 容器也会立即退出 [英] docker container exits immediately even with Console.ReadLine() in a .NET Core console application

查看:26
本文介绍了即使在 .NET Core 控制台应用程序中使用 Console.ReadLine() docker 容器也会立即退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 docker 容器中运行 .NET Core 1.0.0 控制台应用程序.
当我从机器上的 Demo 文件夹中运行 dotnet run 命令时,它工作正常;但是当使用docker run -d --name demo Demo运行时,容器立即退出.

我尝试了 docker logs demo 来检查日志,它只显示来自 Console.WriteLine 的文本:

<块引用>

演示应用程序正在运行...

没有别的.

我已将项目上传到 https://github.com/learningdockerandnetcore/Demo>

项目包含Programs.cs、用于创建Demo镜像的Dockerfileproject.json文件.

解决方案

你应该在交互模式下运行你的容器(使用 -i 选项),但请注意后台进程将被关闭当您运行容器时立即运行,因此请确保您的脚本在前台运行,否则它根本无法运行.

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.

I tried docker logs demo to check the logs and it just shows the text from the Console.WriteLine:

Demo app running...

and nothing else.

I have uploaded the project at https://github.com/learningdockerandnetcore/Demo

The project contains Programs.cs, Dockerfile used to create Demo image, and project.json file.

解决方案

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 容器也会立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆