Over the last four weeks, I’ve been plagued by numerous PHP segfault problems – multiple versions of PHP, on different operating systems, on different hardware, and running completely different codebases.
Yesterday, I ran into a segfault that I couldn’t work around. It is happening with Apache + mod_php, running inside a Centos 6-based Docker container. Docker is hosted on Ubuntu 15.04.
Here are the steps I took to enable core dumps for Apache inside the container, so that I could examine the segfault.
On Ubuntu (the host machine):
- sudo sysctl -w fs.suid_dumpable=2
- sudo sysctl -w kernel.core_pattern=/tmp/core-%e-%s-%u-%g-%p-%t
That’s it. Your Docker container automatically inherits these settings, and Apache will start coredumping without being restarted.
Why Does This Work?
With Docker, because it’s not a virtual machine in the way that VMWare or VirtualBox is, the container inherits the settings of your host operating system. Inherits, and can’t change them inside the container (which is not ideal).
You have to enable coredumps on your host operating system.
Ubuntu 15.04 ships with coredumps already enabled. Ubuntu also ships with an app that gathers coredumps and ships them off to Canonical for inspection – this is the ‘A system error has been detected’ dialog box that appears all too frequently on a modern Ubuntu system.
Ubuntu’s helper app can’t intercept coredumps that occur within a Docker container, so you don’t have to worry about it in there.