Debug ASP.NET Core on Docker with Visual Studio Code

Last Thursday I started reading the Free eBook: “Containerized Docker Application Lifecycle with Microsoft Tools and Platform” by Cesar de la Torre. The book is really easy to read and really gives the reader a glimpse on the way to approach the overall application lifecycle when using containers and Microsoft Technologies. One of the interesting things he mentions is the ability to debug your source code inside a container using Visual Studio or Visual Studio Code, so I decided to try it out and Debug ASP.NET Core on Docker with Visual Studio Code

First be aware of the following prerequisites:

Prerequisites Command
.NET Core 1.1 SDK for Windows Download and install: .NET Core 1.1 SDK for Windows
Docker for Windows Download and install: Docker for Windows (stable)
Visual Studio Code and C# Plugin Download and install from here: Code
Node.js Download and install from here: Node.js v6.9.2
Yeoman From a Command Prompt run the following: npm install -g yo
Generator-docker Run the following command: npm install -g generator-docker
Bower Run the following command: npm install -g bower
Gulp Run the following command: npm install -g gulp

Now let’s create an ASP .NET Core application and debug it inside Docker:

1. Create an ASP .NET Core application
2. Change your application port in Program.cs
3. Create the artifacts needed to Debug on Docker
4. Change dockerTask.ps1
5. Change the docker files
5. Debug your application

You can get a copy of the code here: https://github.com/cmendible/dotnetcore.samples/tree/master/debug.on.docker

Hope it helps!

7 thoughts on “Debug ASP.NET Core on Docker with Visual Studio Code

  1. Hi,Great work!!!! an observation, on the Prerequisites yeoman installation is twice, i thing that the second command must be npm install -g generator-docker
    Bye.

  2. Hi Carlos!
    Could you give me a tip what part of code ensure debugging in a container?
    how can I ensure (what part of code is responsible for that) that VS Code create relation between a container and a debug process?

    1. Hi sorry I couldn’t come back to you any sooner. The files related to debugging are:

      Dockerfile.debug: in line 6 it installs de CRL Debugger in the docker image.
      task.json: you’ll find here the task related to building and composing the image
      launch.json: the pipeTransport in line 27 will start debugging
      dockerTask.ps1: the powershell script that does the rest of the magic (i.e. line 113)

      Hope it helps!!!

Leave a Reply