skip to Main Content

I created a docker enabled project and the docker container runs

But when I click port 80 link

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

enter image description here

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

Open port 80 in Docker Desktop

2

Answers


  1. Chosen as BEST ANSWER

    For the meantime I found the following temporary solution:

    Build Docker Image as described in @Nathan Carlson's post enter image description here

    Then open terminal go to the Dockerfile directory. And enter this docker command manually:

    docker run -it --rm -p 5000:80 --name desiredcontainername projectnameinlowercase
    

    You can specify a different port 5000 is just an example


  2. 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":
    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search