Skip to content

riccardomerlin/docker-dotnet-framework-debug

Repository files navigation

Debug .Net Framework MVC apps running in Docker

In this example we will see how to debug a traditional .Net Framework MVC app that runs in a Docker container.

Get started

  1. Clone this repo.

  2. From the root folder execute the following commands from the shell to get the app running in a Docker container.

    # build solution
    msbuild -p:DeployOnBuild=true -p:PublishProfile=DebugFolderProfile
    
    # build image
    docker build -t asp-net-app:latest .
    
    # create and run container
    docker run --name aspnet-container -p 8080:80 -it asp-net-app:latest
  3. On another shell start the remote debugger in the container.

    # start remote debugger in the container
    docker exec -it aspnet-container "C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe" /nostatus /silent /noauth /anyuser /nosecuritywarn
  4. Open up your browser and load http://localhost:8080. You should see the page shown below.

  5. Now, open up /asp-net-app.sln in Visual Studio 2017.

  6. From the top menu select Debug > Attach to process....

  7. On the Attach to process window select Connection target and click Find.

  8. If the debugger is running (see step 1) you should get a result.

  9. Select the remote debugger found.

  10. Tick Show processes for all users.

  11. Select w3wp.exe and click Attach.

  12. Set a breakpoint on HomeController.cs > About() action.

  13. Go back to the browser page and click the About page link.

  14. Visual Studio debugger should stop on the breakpoint.

Other actions

# stop remote debugger
docker exec -it aspnet-container powershell.exe Stop-Process -Name msvsmon

# stop container
docker stop aspnet-container

# create container and port mapping
docker create --name aspnet-container -p 8080:80 -it asp-net-app:latest

# start container
docker start -ai aspnet-container

Using volumes

As an alternative of copying local files into the container we can use volumes to be able, for example, to make changes to files and see them reflected live into the running container website.

  1. Run the following commands on a shell.
    # build solution
    msbuild -p:DeployOnBuild=true -p:PublishProfile=DebugFolderProfile
    
    # build image for volumes
    docker build -f dockerfile.volume -t asp-net-app:volume .
    
    # create and run container
    docker run -v c:/you_local_path/asp-net-app/bin/Debug/Publish:c:/inetpub/wwwroot --name aspnet-volume-container -p 8080:80 -it asp-net-app:volume
  2. Follow steps from 3 onwards as described in Get started.
  3. Make a change in any file and re-publish.
  4. Refresh the page in the browser and see that the changes are applied.

About

Debug Asp.Net Framework MVC apps running in Docker containers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published