I run docker, command as listed followed, when process occurs core dumped but no core generated.
docker run --privileged -it xxxximage bash
pc info and core config
[root@b4645cba1ca5 home]# uname -a
Linux b4645cba1ca5 4.18.0-193.el8.x86_64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@b4645cba1ca5 home]# ulimit -c
unlimited
[root@b4645cba1ca5 home]# cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e
[root@b4645cba1ca5 home]#
a demo, it will core dumped
#include <stdio.h>
int main(int argc ,char * argv[])
{
printf("hello core\n");
int * p = NULL;
*p = 2;
return 0;
}
[root@b4645cba1ca5 home]# gcc -g -o hello hello.c
[root@b4645cba1ca5 home]# ./hello
hello core
Segmentation fault (core dumped)
[root@b4645cba1ca5 home]#
as the official document says, the generated core file is in the /var/lib/systemd/coredump/ directory, but I found that it is not. Core dumps and systemd
but I modify the /proc/sys/kernel/core_pattern, it can generate core file
[root@b4645cba1ca5 home]# echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern
[root@b4645cba1ca5 home]# cat /proc/sys/kernel/core_pattern
core-%e-%p-%t
[root@b4645cba1ca5 home]# ./hello
hello core
Segmentation fault (core dumped)
[root@b4645cba1ca5 home]# ls -l
total 136
-rw------- 1 root root 380928 Sep 8 16:01 core-hello-61-1694188873
-rwxr-xr-x 1 root root 20552 Sep 8 15:42 hello
-rw-r--r-- 1 root root 151 Sep 8 09:37 hello.c
[root@b4645cba1ca5 home]# date
Fri Sep 8 16:01:24 UTC 2023
[root@b4645cba1ca5 home]#
Does anyone know why? or give some idea?
The default path for docker core_pattern is |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e. For security reasons, I do not add the --privileged parameter when run docker, so it can't modify core_pattern path (read-only system), but I hope that the core file can be generated.