I created a docker enabled project and the docker container runs
It says this page isn’t working, localhost didn’t send any data.
It only works when I press Docker start in visual studio.
What I tried:
I tried running a default Docker Enabled ASP.NET MVC project
I expect that when the container runs and I access the link on the port it should work and give no errors. As the image of the project is running on the container no matter if visual studio is running or not. As was the case here: https://learn.microsoft.com/en-us/training/modules/dotnet-microservices/3-exercise-build-docker-image
I used OBS (recording to see that the debug outputs this command when I run (Docker) in Visual studio
So I tried just using that in a command prompt but doesn’t make it work.
docker exec -i bf3cbddd1c8d695db4106583f8ae863c6c62ab129852f60aa3e056851d4c51e8 /bin/sh -c "if PID=$(pidof dotnet); then kill$PID; fi"
Reproduce:
Create new asp net mvc application with docker enabled.
Docker OS: Linux
2
Answers
For the meantime I found the following temporary solution:
Build Docker Image as described in @Nathan Carlson's post
Then open terminal go to the Dockerfile directory. And enter this docker command manually:
You can specify a different port 5000 is just an example
This behavior is documented here
TL;DR: When running the container from VS it only runs your actual process for F5 / Ctrl+F5. The container is left running during the VS session so it can be reused for the next launch (the project is updated using a mapped volume).
If you would like a version of the image the works w/o VS supporting debugging you can right-click on the Dockerfile and select "Build Docker Image":
FYI:
The command you found and ran is a pre-build step to clear out any dangling dotnet process in the container that may be holding onto your project’s output.