Configure to get core file
Run following commands in a start up script of docker container.
echo '/tmp/core.%h.%e.%t' > /proc/sys/kernel/core_pattern
ulimit -c unlimited
- In some case, default value of
/proc/sys/kernel/core_pattern
is pipe. Then, it should be configured explicitly - Configure size of core file by
ulimit
command
Setting for the program
- Enable debug option if the program is compiled by yourself. Install debug symbol if it's from package manager.
- Do not delete source code in docker image.
Run container
- Use
--privileged
option whendocker run
to allow write permission for/proc/sys/kernel/core_pattern
After segmentation fault
- Check your container ID by
docker ps -a
command - Create docker image from the container by
docker commit
- example)
docker commit -m "coredump" 92b8935a7cd7
(92b8935a7cd7 is container ID)
- example)
-
docker run -it <created image ID> sh
and boot a container in a state immediately after segmentation falut
After boot a container
- Install gdb if it hasn't been installed
- Run
gdb /path/to/binary /path/to/corefile
- Enjoy debugging
Top comments (1)
Awesome article. Only tip, is if you're using docker-compose you can use
privileged: true
from docs in your docker-compose.yml file.