简体   繁体   English

在Docker容器中运行标准.NET控制台应用程序

[英]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.

相关问题 从在 Docker Windows 容器中运行的 .Net 4.8 控制台应用程序连接到本地 SQL Server - Connect to local SQL Server from .Net 4.8 Console Application Running in Docker Windows container 对在Docker容器上运行的C#点网络应用程序进行性能分析 - Profiling a C# dot net application running on a docker container 在Mono Docker容器中运行控制台应用程序 - Run a console application in a Mono Docker container 运行 .NET 核心控制台应用程序 - Running a .NET Core Console Application 为什么在运行ASP.NET Framework 4.7应用程序时docker容器的时间戳错误? - Why is my docker container's timestamp wrong when running an ASP.NET Framework 4.7 application? 在 docker 容器中使用命令行 arguments 调试 .NET 控制台应用程序 - Debugging .NET console app with command line arguments within a docker container 使用.Net Framework 4.6.2在PC上运行.Net Standard 2.0应用程序 - Running a .Net Standard 2.0 Application on a PC with .Net Framework 4.6.2 在 Docker 容器中运行 do.net 6 应用程序时出现不变文化问题 - Invariant culture issue while running the dotnet 6 application in a Docker Container 在Docker上运行.NET Framework控制台应用服务 - Running .NET framework console-app service on Docker Asp.NET 核心 WebAPI 未在 docker 容器中运行 - Asp.NET Core WebAPI not running in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM