Reputation: 1611
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.
Upvotes: 3
Views: 8095
Reputation: 1611
In the end, the fix was to change the ENTRYPOINT to a CMD in the dockerfile. 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.
Upvotes: 5
Reputation: 3832
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.
Upvotes: 2