Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate core file in docker container?

using ulimit command, i set core file size.

ulimit -c unlimited

and I compiled c source code using gcc - g option. then a.out generated. after command

./a.out there is runtime error .

(core dumped)

but core file was not generated.(ex. core.294340)

how to generated core file?

like image 339
leeyc Avatar asked Feb 05 '15 03:02

leeyc


People also ask

How is core file generated?

Core file and crash dumps are generated when a process or application terminates abnormally. You must configure your system to allow Directory Server to generate a core file if the server crashes.

What generates a core dump?

Core dumps are files the system creates when a process running in memory does not finish. The portion of memory that the process was using is then dumped to a file. This can be quite helpful when debugging your scripts. Core dumps typically have a file name like: core.5876.

How many cores does a docker container have?

On windows, a container defaults to using two CPUs. If hyperthreading is available this is one core and two logical processors. If hyperthreading is not available this is two cores and two logical processors.


2 Answers

First make sure the container will write the cores to an existing location in the container filesystem. The core generation settings are set in the host, not in the container. Example:

echo '/cores/core.%e.%p' | sudo tee /proc/sys/kernel/core_pattern

will generate cores in the folder /cores.

In your Dockerfile, create that folder:

RUN mkdir /cores

You need to specify the core size limit; the ulimit shell command would not work, cause it only affects at the current shell. You need to use the docker run option --ulimit with a soft and hard limit. After building the Docker image, run the container with something like:

docker run --ulimit core=-1 --mount source=coredumps_volume,target=/cores ab3ca583c907 ./a.out

where coredumps_volume is a volume you already created where the core will persist after the container is terminated. E.g.

docker volume create coredumps_volume
like image 91
Gerardo Hernandez Avatar answered Oct 13 '22 19:10

Gerardo Hernandez


If you want to generate a core dump of an existing process, say using gcore, you need to start the container with --cap-add=SYS_PTRACE to allow a debugger running as root inside the container to attach to the process. (For core dumps on signals, see the other answer)

like image 31
Gert van den Berg Avatar answered Oct 13 '22 19:10

Gert van den Berg