I want to run a simple dotnet core console app in a container interactively. I am not able to do that and the container simply starts and then exits immediately without fully running the program.
All that the console app has is the followng three statements.
Console.WriteLine("Hello World!");
var readText = Console.ReadLine(); // Wait for me to enter some text
Console.WriteLine(readText);
The last two lines make it interactive.
When I run the container, it prints the Hello World! But then it immediately exits, without waiting for me enter some text. Why? what am I missing?
I was able to run a dotnet core web app in the container in a similar manner, and I am able to map the ports outside and within the container to successfully browse the web app. But when it comes to console app, I am stumped.
I guess there could be something very simple that I am missing. Driving me nuts
The steps to reproduce as described below.
- Launch Vs2019 and create a new .net core console project.
- Add a couple of statements to make it interactive.
- Add Docker support to the created project. Right click the project, Add -> select Container Orchestrator Support
- Now visual studio creates a set of files and changes the csproj file as well.
- In a powershell navigate to folder having the solution file. Run the command "docker-compose up"
- Once the images are built, and containers are up and running, we can see start to see the problem.
- We can see here Hello-World!. But it does not wait for me to type something. Type docker ps -a and see a container that is exited. When I try to start that using docker start -i or docker start -a, the container starts but exits immediately. What should I do to make the container run so that i can type something for my app running in it read? You can see in the docker desktop as well. Even if I start them(using the start button available with the docker desktop UI against each container), it simply stops again.
- I had run web apps in containers. With proper port mapping, a web app running inside of a container can be accessed from outside. I had created a dotnet core web app in similar lines described above, modified the docker-compose file to include port mapping(shown below) and when I do docker-compose up, the app is up and running. But with a console app, the container simply exits.