如何在Docker容器中禁用核心文件转储

问题描述 投票:13回答:2

我的PHP容器运行puppeteer生成PDF。通过生成PDF文档,它还在我的容器内创建了两个核心转储文件。我不确定它们的真正来源。

主机/服务器是CentOS 7。

我已检查以下内容:

  1. 没有应用程序错误日志,Browsershot / Puppeteer正在运行,没有错误。
  2. /var/log/messages中找不到错误日志(例如segfault)

我尝试禁用核心转储

根据https://linux-audit.com/understand-and-configure-core-dumps-work-on-linux/的“禁用核心转储”部分,我已经完成:

  1. /etc/security/limits.conf添加以下内容
* soft core 0
* hard core 0
  1. 通过:echo “ulimit -c 0 > /dev/null 2>&1” > /etc/profile.d/disable-coredumps.sh

  2. 创建了disable-core-dumps.sh
  3. 将以下内容添加到/etc/systemd/coredump.conf

[Coredump]

Storage=none
ProcessSizeMax=0
  1. 并且重新启动服务器和容器

  2. 我也试图将ulimit -c 0设置在容器内(高山)

以上所有技巧都不适合我。人偶每次生成PDF时,总是会创建两个核心转储文件,如下所示:

core.131 core.52

核心文件如下:

Core dump file content

有人可以帮我禁用核心转储吗?非常感谢。

docker docker-compose puppeteer alpine coredump
2个回答
3
投票

您必须使用选项--ulimit core=0启动容器以禁用核心转储。

参考:https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-in-container---ulimit

示例

在主机上,将核心转储路径临时设置为/tmp以进行验证:

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

照常启动容器并强制进行核心转储:

docker run --rm -it bash
(inside the container)
# yes > /dev/null &
# kill -SIGABRT $(pidof yes)
# ls /tmp
(shows core.yes.<pid>)

现在,带有--ulimit core=0

docker run --ulimit core=0 --rm -it bash
(inside the container)
# yes > /dev/null &
# kill -SIGABRT $(pidof yes)
# ls /tmp
(No entries)

2
投票

我在docker swarm服务上也有这个问题,-ulimit core = 0在我在以下命令中使用的swarm服务中不起作用,并在docker swarm服务中为我工作了!

sysctl -w kernel.core_pattern = / dev / null

© www.soinside.com 2019 - 2024. All rights reserved.