I am trying to run a very simple console application as a windows docker container. I have a docker file shown below using the "dotnet-framework:4.7.2-runtime-windowsservercore-1803" base image.
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"
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
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. 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. You can examine docker logs
to find out a reason.