如何在Docker容器中生成核心文件? [英] how to generate core file in docker container?

查看:192
本文介绍了如何在Docker容器中生成核心文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ulimit命令,我设置核心文件大小。

using ulimit command, i set core file size.

ulimit -c unlimited

,然后使用gcc-g选项编译了c源代码。然后生成

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

。/a.out
后出现运行时错误。

./a.out there is runtime error .

(core dumped)

但未生成核心文件。(例如core.294340)

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

如何生成核心文件?

推荐答案

首先确保容器将内核写入容器文件系统中的现有位置。核心生成设置是在主机而不是容器中设置的。例如:

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

将在文件夹/ cores中生成内核。

will generate cores in the folder /cores.

在Dockerfile中,创建该文件夹:

In your Dockerfile, create that folder:

RUN mkdir /cores

您需要指定核心大小限制; ulimit shell命令将不起作用,因为它仅影响当前的shell。您需要使用具有软限制和硬限制的docker run选项--ulimit。构建Docker映像后,使用以下命令运行容器:

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

其中coredumps_volume是您已经创建的卷容器终止后核心将继续存在的位置。例如,

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

这篇关于如何在Docker容器中生成核心文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆