构建docker镜像时如何修改`core_pattern` [英] How to modify the `core_pattern` when building docker image

查看:163
本文介绍了构建docker镜像时如何修改`core_pattern`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在构建docker镜像的时候修改core_pattern,我的docker文件是这样的:

I want to modify the core_pattern when building docker image, and my docker file is like this:

FROM centos:7
RUN echo "core-%e" > /proc/sys/kernel/core_pattern

然后我运行 docker build 得到一个错误

Then I ran docker build and I get an error

/bin/sh: /proc/sys/kernel/core_pattern: Read-only file system

有人帮忙吗?

推荐答案

我自己也需要这个,我才知道怎么做.它与 docker 无关,而是与一般的 linux 相关.我正在使用 ubuntu,而且我 99% 确定 centos 在这方面的表现是一样的.

I needed this myself, I just found out how. it is not related to docker, but to linux in general. I am using ubuntu and I am 99% certain centos will behave the same in this regard.

通过sysctl命令编辑.

查看示例

bash$ cat /proc/sys/kernel/core_pattern 
|/usr/share/apport/apport %p %s %c %d %P %E
bash$ sudo sysctl -w kernel.core_pattern="|/usr/share/apport/apport-kde %p %s %c %d %P %E"
kernel.core_pattern = |/usr/share/apport/apport-kde %p %s %c %d %P %E
bash$ cat /proc/sys/kernel/core_pattern 
|/usr/share/apport/apport-kde %p %s %c %d %P %E
bash$

注意以| 开头的值是表示命令.核心转储将作为 STDIN 发送到命令

note that value starting with | is to express commands. the core dump will be sent to the command as STDIN

既然你问了关于 docker 的问题,我也提供一个兼容的答案.

Since you asked your question about docker, let me also provide a compatible answer.

FROM centos:7
RUN sudo sysctl -w kernel.core_pattern="core-%e"

有关您可以在文件中使用的核心模式的更多信息,而不仅仅是 %e,请参阅 https://sigquit.wordpress.com/2009/03/13/the-core-pattern/

for more info on the core pattern you can use in your file, instead of just %e, see https://sigquit.wordpress.com/2009/03/13/the-core-pattern/

还有另一个有更多细节的相关问题/答案

also another related question/answer that has more details

https://unix.stackexchange.com/questions/343275/why-is-editing-core-pattern-restricted

这篇关于构建docker镜像时如何修改`core_pattern`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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