How to automatically feed in Docker environment NET program to generate Dump

Posted by Pantho on Mon, 31 Jan 2022 15:26:44 +0100


Previously, the "first-line code farmer" wrote an article on how to dump automatically under windows. It happened that he had a demand for dump under the docker environment. Therefore, this article is based on the article of the boss.


dotnet-dump (
ProcDump for linux (


Dotnet dump is officially launched by Microsoft NET global tools, installation and use are very simple.

dotnet tool install --global dotnet-dump


dotnet-dump collect --process-id 1902 # pid

But it can't dump automatically (or I don't know), so this article mainly discusses the following tool

ProcDump for linux

This tool is a community linux porting version of ProcDump, but the main developers are also Microsoft employees.
It can automatically dump according to CPU occupation, memory occupation, number of threads, etc., so that we can deal with the scene where the dump file needs to be analyzed when the program is abnormal.

Add the following command to Dockerfile:
Note that we should add it to the runtime image, and it is better to build a basic image instead of installing it every time.

# final stage/image

# Install required dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        wget \
        gdb \

# Install procdump
RUN wget -O procdump.deb \
    && dpkg -i procdump.deb \
    && rm procdump.deb

This article is based on the aspnet:5.0 image, i.e. debian 10. If it is based on other images, you can find the corresponding package in the following directory
Also refer to the installation instructions provided by the author

Because the docker container can not easily execute multiple processes at the same time at startup, we need an sh file to execute dotnet and procdump at the same time at startup.
Because I personally don't like to rely on other files besides Dockerfile, I directly created the sh file in Dockerfile

RUN echo "#!/bin/bash \n\
procdump -M 200 -w dotnet & \n\
dotnet \$1 \n\
" > ./
RUN chmod +x ./
ENTRYPOINT ["./", "<YourApp>.dll"]

If necessary, you can also create a start SH, the content is

procdump -M 200 -w dotnet &
dotnet $1

Dockerfile changed to

RUN chmod +x ./
ENTRYPOINT ["./", "<YourApp>.dll"]

In this way, when docker run s, dotnet and procdump will be started at the same time, and when the memory is greater than 200M, it will dump automatically.
It should also be noted that -- privileged needs to be added when docker runs to improve permissions. For example, docker run --privileged -it xx

The parameters of procdump are

Usage: procdump [OPTIONS...] TARGET
      -h          Prints this help screen
      -C          When CPU Exceeds or equals the specified value (0 to 100 * nCPU)Core dump generation is triggered when.
      -c          When CPU Less than the specified value (0 to 100) * nCPU)Core dump generation is triggered when.
      -M          When the memory commit exceeds or equals the specified value(MB)Trigger core dump generation when
      -m          When the memory commit is less than the specified value( MB)Core dump generation is triggered when.
      -T          Triggered when the number of threads exceeds or equals the specified value.
      -F          Triggered when the file descriptor count exceeds or equals the specified value.
      -I          Polling frequency in milliseconds (default is 1000)
      -n          Number of core dumps to write before exiting (default is 1)
      -s          Consecutive seconds before dump is written (default is 10)
      -d          Writes diagnostic logs to syslog
    TARGET Choose one of the following:
      -p          Process pid
      -w          Name of the process

For example, the following command means to create a dump file when the CPU utilization is > = 65% or the memory is > = 100 MB

procdump -C 65 -M 100 -p 1234


Persistence of dump file
As we all know, if the docker container disappears, the dump file in it will also disappear.
Therefore, you need to output the dump file to a specified volume that has been persistently mounted. Unfortunately, at present, procdump for linux does not have an output parameter to control the output directory, which will only be generated in the same level directory of the application, so you need to move it manually.
I think PR has been mentioned. In the future, a -o parameter will be added to control the output.

reference resources

Topics: ASP.NET Docker .NET dump