[英]Running a standard .NET Console Application in docker container
I am trying to run a very simple console application as a windows docker container. 我试图将一个非常简单的控制台应用程序作为Windows docker容器运行。 I have a docker file shown below using the "dotnet-framework:4.7.2-runtime-windowsservercore-1803" base image.
我有一个使用“ dotnet-framework:4.7.2-runtime-windowsservercore-1803”基础映像显示的泊坞窗文件。
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT "DockerConsoleApp.exe"
The console application just outputs "Hello World" to a log file every 5 seconds" 控制台应用程序仅每5秒将“ Hello World”输出到日志文件”
static void Main(string[] args)
{
while (true)
{
try
{
Thread.Sleep(5000);
_logger.Info("Hello Wolrd");
}
catch (Exception e)
{
//handle the exception
Console.Error.WriteLine(e);
}
}
}
I am using the following docker compose file 我正在使用以下docker compose文件
version: '3.4'
services:
dockerconsoleapp:
image: dockerconsoleapp:dev
build:
context: .\
args:
source: obj\Docker\publish
volumes:
- C:\Users\user\source\repos\DockerConsoleApp\DockerConsoleApp:C:\app
- C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Remote Debugger:C:\remote_debugger:ro
- C:\Users\user\source\repos\DockerConsoleApp\VolumeTest:C:\app\logs
The problem is that as soon as I manually build or run "docker-compose up -d" The container is created and then immediately dies. 问题是,一旦我手动构建或运行“ docker-compose up -d”,就会创建容器,然后立即死亡。 I would expect that the container should stay up given that the application is being called in the entrypoint and the application should just keep going unless manually stopped.
我希望容器可以保持打开状态,因为在入口点中正在调用应用程序,除非手动停止,否则应用程序应该继续运行。
Your container died most likely as a result of exception in your ENTRYPOINT
or ENTRYPOINT
itself not being valid. 您的容器很可能是由于
ENTRYPOINT
异常或ENTRYPOINT
本身无效而导致的死亡。 You can examine docker logs
to find out a reason. 您可以检查
docker logs
以找出原因。
In the end, the fix was to change the ENTRYPOINT to a CMD in the dockerfile. 最后,解决方法是将dockerfile中的ENTRYPOINT更改为CMD。 See below.
见下文。
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
CMD ["DockerConsoleApp.exe"]
I have let this run overnight and the container is now up 15 hours. 我已经让它运行了一整夜,现在容器可以用15个小时了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.