how to generate core file in docker container?

前端 未结 2 1266
南方客
南方客 2021-01-31 21:03

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 comm

相关标签:
2条回答
  • 2021-01-31 21:28

    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
    
    0 讨论(0)
  • 2021-01-31 21:32

    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)

    0 讨论(0)
提交回复
热议问题