In this example we will see how to debug a traditional .Net Framework MVC app that runs in a Docker container.
-
Clone this repo.
-
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
-
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
-
Open up your browser and load
http://localhost:8080
. You should see the page shown below. -
Now, open up
/asp-net-app.sln
in Visual Studio 2017. -
From the top menu select
Debug > Attach to process...
. -
On the
Attach to process
window selectConnection target
and clickFind
. -
If the debugger is running (see step 1) you should get a result.
-
Select the remote debugger found.
-
Tick
Show processes for all users
. -
Select
w3wp.exe
and clickAttach
. -
Set a breakpoint on
HomeController.cs > About()
action. -
Go back to the browser page and click the
About
page link. -
Visual Studio debugger should stop on the breakpoint.
# 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
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.
- 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
- Follow steps from 3 onwards as described in Get started.
- Make a change in any file and re-publish.
- Refresh the page in the browser and see that the changes are applied.