Docker container running C++ program, sometimes crash, but no log, no warning. Having previously mastered Coredump debugging, this article tries it in containers.

operation

First look at the core size:

$ ulimit -a | grep core
core file size          (blocks, -c) 0
Copy the code

Settings:

$ulimit -c unlimited
Copy the code

Check it again:

$ ulimit -a | grep core
core file size          (blocks, -c) unlimited
Copy the code

Set the path

$ sudo echo 'core.%t.%e.%p' | sudo tee /proc/sys/kernel/core_pattern
Copy the code

Run the image:

docker run -v /home:/home  -it latelee/myserver bash
Copy the code

Enter the corresponding program directory:

# cd /home/latelee/docker/test/myserver/
Copy the code

Run test program with segment error:

# ./myserver
Segmentation fault (core dumped)
Copy the code

Check whether:

# ls
Dockerfile  core.1535079291.myserver.11  entrypoint.sh  config.ini  myserver
Copy the code

Coredump file generated as core. 1535079291. Myserver. 11

Core Settings take effect permanently

Edit/etc/security/limits. The conf file, modify the core relevant configuration items, as follows:

*               soft    core            unlimitedroot            hard    core            unlimited
Copy the code

Edit the /etc/sysctl.conf file and add:

kernel.core_pattern = core.%t.%e.%p
Copy the code

Note: The above two files need root permission to open.

summary

0. The program must be compiled using -g, that is, with debugging information, otherwise, even with Coredump, the problem is invisible. 1. Run ulimit -c unlimited on the host and set the coredump path. 2. Execute the program in the Docker container.

experience

Docker run with –ulimit core=-1 –security-opt seccomp=unconfined Because I usually use docker-compose to compose containers, I don’t know how to write docker-compose. Yml file, so I will not use it for the time being. 2. You are advised to set the coredump file path in/TMP or a separate mounted directory. The above is only for demonstration and has no practical guidance.