I created the following simple dotnet core console application from Visual Studio 2019.
Console.WriteLine("Hello World!");
var readText = Console.ReadLine();
Console.WriteLine(readText);
Then 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.
In a command prompt, I now navigate to the folder where the docker-compose file is present and issue the following command
docker-compose run <service name from docker-compose.yml file>
Specifically for my case it would be
docker-compose run dokconsoleapp
Where dokconsoleapp is the service name defined inside of docker-compose file.
This builds the image and my console app is launched and run inside of the container interactively.
And when the app exits, the container stops. Now when I want to run again, I issue the same command again. The app runs as expected. But curiously the app is launched in a new container, not reusing the existing stopped container.
So I run the command three times and each time a new container is created, see in docker desktop.
Now my question is, I am just curious, is there way here with docker-compose run, to reuse the existing container, rather than creating new ones.
Note that the command
docker-compose up
does not work as the container it creates is not interactive. So I have to use 'run' only. More details here.