How to provide console input for a Visual Studio .NET Core project using container orchestration?

Viewed 243

I have converted a .NET Core console application to a Dockerized application using Visual Studio 2017's built in Container Orchestration features. VS created a Dockerfile and a docker-compose file. I am able to run the application within the container successfully.

The problem is that in some cases the application requires input at the console (e.g. it asks a question and the user must answer yes or no). The app uses Console.ReadKey() or Console.ReadLine() as appropriate.

When running a .NET Core console app traditionally, a terminal window pops up that displays the app's output and accepts input. However, when I switched to Docker, the console output now appears in one of the debug panels on the bottom of the screen, and I'm not able to provide any input.

The app does not fail to run, it simply blocks indefinitely at the Console.ReadLine() command.

Is there a way to make Visual Studio run the container within a traditional terminal that can accept user input?

1 Answers

Kahbazi is right, you need to run the docker container with -i (interactive mode) and -t (tty mode). For example: docker run -i -t --name containerName imageName

Ensure not to run it in detached mode too, or else you won't be prompted for input since the container will run in the background.

I was unable to find a way to do this through Visual Studio, so I used docker through the command line instead.

Related