I created the following simple dotnet core console application from Visual Studio 2019.
Console.WriteLine("Hello World!");
var readText = Console.ReadLine();
Console.WriteLine(readText);
When I press F5, the program waits for me at Console.ReadLine till I enter some text. When I type some text and press enter, the same text is displayed to me back.
Now I add docker support to this console project. I have written the step by step instructions in another so question to add the docker support.
After I add the docker support, in a command prompt, I navigate to the folder where the docker-compose file is present and issue the command,
docker-compose up
the application runs, prints the Hello World!. Then apparently it stops and waits for me to input some text. But as I type the text and press enter, nothing happens. Seems that the input I am giving at the console is not being communicated to the app running inside of the container.
What am I missing? Why is the app running inside of the container not taking my input? It only takes Ctrl+C after which the container iteself exits.
Note, if the container exits immediately, then you have to add the following to the docker-compose file as explained in the same so question's answer. This will prevent the container from exiting immediately.
stdin_open: true
tty: true