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
Then I ran docker build
and I get an error
/bin/sh: /proc/sys/kernel/core_pattern: Read-only file system
Anybody help?
5
Answers
I found another way. Add echo "core-%e" | sudo tee /proc/sys/kernel/core_pattern &> /dev/null into the ~/.bashrc.
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.
it is edited via
sysctl
command.see example
note that value starting with
|
is to express commands. the core dump will be sent to the command as STDINSince you asked your question about docker, let me also provide a compatible answer.
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
It’s not possible to have different core_pattern in the host and in the container at the same time, as docker is sharing the kernel with its host.
However, you can run the container in privileged mode and change core_pattern from inside a container during startup/runtime (modify core_pattern in CMD section or execute os command from inside).
But keep in mind that this setting will not be automatically restored after the container finished (until you do it programmatically).
when using docker, those files are protected that you can’t change anyway, even using
sudo sysctl
to write. (At least in my situation).so you need to run docker cmd in your local terminal like this (in your case):
after you connect to this image, you will find the core pattern has changed.
If you run it in a container, using ‘–privileged’ option in run cmd.
Then run in container:
Here is my example: