skip to Main Content

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


  1. Chosen as BEST ANSWER

    I found another way. Add echo "core-%e" | sudo tee /proc/sys/kernel/core_pattern &> /dev/null into the ~/.bashrc.


  2. 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

    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$
    

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

    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"
    

    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

    Login or Signup to reply.
  3. 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).

    Login or Signup to reply.
  4. 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):

    docker run --privileged <the docker image ID> sysctl -w kernel.core_pattern=core-%e
    

    after you connect to this image, you will find the core pattern has changed.

    Login or Signup to reply.
  5. If you run it in a container, using ‘–privileged’ option in run cmd.

    docker run --privileged <the docker image ID>
    

    Then run in container:

    sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
    

    Here is my example:

    ylin30@yi-IdeaPad:~/TS-Benchmark/tsdb-test$ sudo docker run -d --privileged --name ticktock -h ticktock -p 6182:6182 -p 6181:6181 --cpus="1" -m 4g ytyou/ticktock:latest --tsdb.timestamp.resolution millisecond --tcp.buffer.size 3mb
    7078cfa224eadcfa76a0a6938214f99b17f9d295fc581580a63fdc4dc3185874
    ylin30@yi-IdeaPad:~/TS-Benchmark/tsdb-test$ sudo docker exec -u 0 -it ticktock /bin/bash
    root@ticktock:/tmp# sysctl kernel.core_pattern
    kernel.core_pattern = |/usr/share/apport/apport %p %s %c %d %P %E
    root@ticktock:/tmp# sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
    kernel.core_pattern = /tmp/core-%e.%p.%h.%t
    root@ticktock:/tmp# sysctl kernel.core_pattern
    kernel.core_pattern = /tmp/core-%e.%p.%h.%t
    root@ticktock:/tmp#
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search