4

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.

4
  • 1
    You probably received exception. Check docker logs for your container Commented Jun 26, 2019 at 13:31
  • docker logs pointed my right. The error was stating that DockerConsoleApp was not recognized as an internal command. Nor was any other variation of it e.g. .\DockerConsoleApp etc. I will update with the fix Commented Jun 26, 2019 at 14:16
  • Well that means that your container image is not valid, nothing to do with docker-compose or docker in general. What do you mean by pointed my right? Commented Jun 26, 2019 at 14:17
  • apologies typo. the docke logs pointed me in the right direction. I added "SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]" to the dockerfile under the FROM line. I then changed the entrypoint to "ENTRYPOINT ".\DockerConsoleApp.exe". This allowed it to run longer but it then exited after 10 seconds Commented Jun 26, 2019 at 14:32

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

docker logs is now just outputting ".\DockerConsoleApp.exe". I believe the exe is still not being run as there is nothing coming out into my local volume location
This seems to be generated by Visual Studio. Craft your own dockerfile to understand how docker works. I don't see any configuration being specified where your log shall go per your entrypoint. You can just output to console from your application to verify it runs instead of logging locally

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.