Are you open to upgrading to .Net Core 3.0 (.Net Core 2.2 is going out of support in a few days: 12/23/2019)

If you're open to that you can take advantage of the new tool dotnet-trace which supports running in a linux container and can be used with the tools in Visual Studio.

Here are the steps I used to add it to my project:

  1. Change your base image to use the sdk image (needed to install the tool).
  2. Add installing the tool to the image:
RUN dotnet tool install --global dotnet-trace
ENV PATH $PATH:/root/.dotnet/tools

Alternatively if you don’t want to add it in your image you can run the following commands in a running container (as long as it as based on the SDK image):

dotnet tool install --global dotnet-trace
export PATH="$PATH:/root/.dotnet/tools"
  1. Start the project without debugging (Ctrl+F5)

  2. Use the Containers Tool Window to open a terminal window

Run the command:

dotnet-trace collect --process-id $(pidof dotnet) --providers Microsoft-DotNETCore-SampleProfiler

When you are done collecting press enter or Ctrl+C to end the collection

This will crate a file called “trace.nettrace”

By default that /app folder that file would be created in is volume mapped to your project folder. You can open the file from there in VS.

Answer from Nathan Carlson - MSFT on Stack Overflow
🌐
GitHub
github.com › dotnet › diagnostics › issues › 810
Support `dotnet trace` running in a sidecar container · Issue #810 · dotnet/diagnostics
February 7, 2020 - Run a containerized ASP.NET Core app within a container. docker run -it -p 8000:80 --name aspnetapp mcr.microsoft.com/dotnet/core/samples:aspnetapp Build a image which contains the dotnet trace tool FROM mcr.microsoft.com/dotnet/core/sdk...
Author   dotnet
🌐
Jeppe Andersen Blog
nocture.dk › posts › .net core diagnostics tools and containers
.NET Core Diagnostics Tools and Containers | Jeppe Andersen Blog
June 17, 2020 - # Start the application, with a bind mount on /tmp/data on the host to /data inside the container docker run --name diagnosticsapp -p 8000:80 -v "/tmp/data:/data" -d diagnosticsapp # Collect a trace and write it to the volume docker exec -it diagnosticsapp /tools/dotnet-trace collect -o /data/trace.nettrace -p 1
🌐
Microsoft
devblogs.microsoft.com › dev blogs › .net blog › collecting .net core linux container cpu traces from a sidecar container
Collecting .NET Core Linux Container CPU Traces from a Sidecar Container - .NET Blog
March 7, 2019 - user@host ~/project/webapi $ docker run -it --pid=container:application --net=container:application -v shared-tmp:/tmp --cap-add ALL --privileged --name sidecar sidecar · Inside the sidecar container, collect CPU traces for the dotnet process (or your .NET Core application process if it is published as self-contained), which usually has PID of 1, but may vary depending on what else you are running in the application container before running the application.
🌐
Medium
medium.com › @davidsilwal › diagnosing-net-aaf5b6821486
Diagnosing .NET Applications in Docker with dotnet-dump, dotnet-counters, dotnet-gcdump, and dotnet-trace | by David Silwal | Medium
February 19, 2025 - The .NET ecosystem offers a robust set of diagnostic tools designed to assist in troubleshliooting applications, even when they are deployed within Docker containers. Tools such as dotnet-dump, dotnet-counters, dotnet-gcdump, and dotnet-trace enable you to gather critical runtime insights seamlessly, without disrupting the application’s operation.
🌐
Medium
ademar-goncalves.medium.com › net-core-diagnostics-in-docker-8be08d3eb4d7
.NET Core Diagnostics in Docker. In .NET Core 3.0, Microsoft introduced… | by Ademar Gonçalves | Medium
October 11, 2021 - For example, if you’re running .NET Core on x64 Ubuntu, you can acquire the dotnet-trace from https://aka.ms/dotnet-trace/linux-x64. It’s possible to create a Dockerfile with a multi-stage build that installs the tools in a build stage and then copies the binaries into the final image.
🌐
my tech ramblings
mytechramblings.com › posts › profiling-a-net-app-with-dotnet-cli-diagnostic-tools
Profiling a .NET6 app running in a linux container with dotnet-trace, dotnet-dump, dotnet-counters, dotnet-gcdump and Visual Studio :: my tech ramblings — A blog for writing about my techie ramblings
March 1, 2022 - ./dotnet-trace collect --process-id 1 --duration 00:00:30 · The collect command collects a diagnostic trace from a running process. The -p|--process-id parameter specifies the process id to collect the trace, in this case we’re inside a docker container so the PID is always 1.
🌐
GitHub
github.com › mjrousos › ContainerProfiling
GitHub - mjrousos/ContainerProfiling: Instructions for profiling .NET Core apps in Docker/K8s containers using dotnet trace or PerfCollect
Instructions for profiling .NET Core apps in Docker/K8s containers using dotnet trace or PerfCollect - mjrousos/ContainerProfiling
Author   mjrousos
🌐
Im5tu
im5tu.io › article › 2020 › 06 › diagnostics-in-.net-core-3-an-alternative-approach-to-using-dotnet-counters-with-docker
Diagnostics in .Net Core 3: An alternative approach to using dotnet-counters with Docker | June | 2020 | Articles | CodeWithStu's Blog
June 25, 2020 - Now you should be able to run dotnet-counters, dotnet-dump & dotnet-trace as normal. If you need to copy any files from the container then you need to run the following from the host machine: docker cp <ID>:<path-to-file-in-container> <copy-to-path-on-host> #Example: docker cp fac2377f3e87:/tools/output/trace.nettrace ./output/trace.nettrace
Find elsewhere
🌐
GitHub
github.com › dotnet › dotnet-docker › issues › 1672
Add `dotnet trace` tooling in base image? · Issue #1672 · dotnet/dotnet-docker
February 6, 2020 - Can we add vance's dotnet trace tooling to the mcr.microsoft.com/dotnet/core/aspnet:3.1? Trying to do this manually in a Dockerfile results in: Step 31/36 : RUN dotnet tool install --global dotnet-trace ---> Running in 78e25001ddc4 It was not possible to find any installed .NET Core SDKs Did you mean to run .NET Core SDK commands?
Author   dotnet
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › core › diagnostics › diagnostics-in-containers
Collect diagnostics in Linux containers - .NET | Microsoft Learn
Learn how .NET diagnostics tools for gathering performance traces and collecting dumps can be used in Linux containers.
🌐
Thecloudblog
thecloudblog.net › the cloud blog › posts › tracing and profiling a .net core application on azure kubernetes service with a sidecar container
Tracing and Profiling a .NET Core Application on Azure Kubernetes Service with a Sidecar Container | The Cloud Blog
February 3, 2021 - Populate the file with the following code, which instructs Docker to bundle the necessary tools inside an image. FROM mcr.microsoft.com/dotnet/sdk:5.0 as tools RUN dotnet tool install --tool-path /tools dotnet-trace RUN dotnet tool install --tool-path /tools dotnet-dump RUN dotnet tool install --tool-path /tools dotnet-counters FROM mcr.microsoft.com/dotnet/runtime:5.0 AS runtime COPY --from=tools /tools /tools ENV PATH="/tools:${PATH}" WORKDIR /tools
🌐
Onurgumus
onurgumus.github.io › 2020 › 12 › 05 › How-to-diagnose-dotnet-in-containers.html
How to diagnose a .net process running inside Kubernetes/docker | Onur Gumus’s blog
December 5, 2020 - If you do use WSL with docker desktop, the /.kube/config file is shared within windows and WSL. ... Download .net core SDK: Now we will need diagnostic tools and for the installation of these tools we need .net SDK installed since typically production containers won’t ship with these tools (unless you a sidecar). Get the relevant SDK from https://dotnet.microsoft.com/download/dotnet-core.
🌐
JetBrains
jetbrains.com › help › profiler › Profile_Application_in_Docker_Container.html
Profile Application in Docker Container | dotTrace Documentation
March 21, 2024 - To profile a .NET application running inside a Docker container, use the dotTrace command-line profiler.
🌐
DevOpsSchool.com
devopsschool.com › blog › dotnet-trace-a-complete-dotnet-trace-tutorials-guide
dotnet-trace: A Complete dotnet-trace Tutorials Guide
November 25, 2025 - Windows, Linux, macOS, Docker, K8s. CPU, GC, threads, allocations, exceptions, etc., from the runtime level. ... Other trace analysis tools that support .nettrace or converted formats. You can demonstrate effect of code changes, GC settings, async vs sync, etc., visually. # List .NET processes dotnet-trace ps # Collect basic trace dotnet-trace collect --process-id <pid> # Collect CPU trace for 2 min dotnet-trace collect --process-id <pid> --profile cpu-sampling --duration 00:02:00 --output cpu.nettrace # Collect GC-verbose trace dotnet-trace collect --process-id <pid> --profile gc-verbose --du
🌐
Green Thinking
chrisgilbert1.wordpress.com › 2017 › 02 › 09 › docker-and-net-core-linux-performance-tracing
Docker and .NET Core Linux Performance Tracing – Green Thinking
June 24, 2020 - Eventually I came up with a Dockerfile that looks like this: FROM microsoft/dotnet WORKDIR /app RUN apt-get -qq update RUN apt-get -qq install -y lttng-tools liblttng-ust-dev linux-tools unzip zip coreutils binutils RUN mv /usr/bin/perf /tmp RUN ln -s /usr/bin/perf_3.16 /usr/bin/perf RUN curl -s https://raw.githubusercontent.com/dotnet/corefx-tools/master/src/performance/perfcollect/perfcollect --output perfcollect && chmod 755 perfcollect # Set tracing environment variables.
🌐
Stack Overflow
stackoverflow.com › questions › 63672180 › c-sharp-dotnet-app-deployed-on-kubernetes-performance-diagnostic-using-dotnet-tr
docker - C# dotnet app deployed on kubernetes performance diagnostic using dotnet trace and counters - Stack Overflow
apiVersion: apps/v1 kind: Deployment metadata: name: demo-dotnet-diagnostics spec: replicas: 1 selector: matchLabels: app: demo-diagnostics template: metadata: labels: app: demo-diagnostics spec: shareProcessNamespace: true containers: - name: demo-app image: gcr.io/qp-fda-mystudies-2020-07/dotnetapp:latest ports: - containerPort: 8080 volumeMounts: - name: dotnet-diagnostics mountPath: /tmp - name: demo-diagnostics image: gcr.io/qp-fda-mystudies-2020-07/diagnostics:latest stdin: true tty: true command: ["/bin/sh","-c"] args: ["dotnet-trace collect -p 1; dotnet-counters monitor -p 1"] volumeMounts: - name: dotnet-diagnostics mountPath: /tmp volumes: - name: dotnet-diagnostics emptyDir: {}