How do I start php7.0-fpm with supervisord?

I am trying to build a dockerized ubuntu 16.04lts with apache2 and nginx with php7.0-fpm

Commands I have used but did not work

[program:php-fpm7.0]
command = /usr/sbin/php-fpm7.0 --daemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

and

[program:php-fpm7.0]
command = /usr/sbin/php-fpm7.0 -c /etc/php/7.0/fpm/php-fpm.conf
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

and

[program:php-fpm7.0]
command = /usr/sbin/php-fpm7.0 -c /etc/php/7.0/fpm
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

Below are the error logs from docker when I try to run as containers

from the apache2 container

2016-06-26 20:04:21,488 CRIT Set uid to user 0
2016-06-26 20:04:21,496 INFO RPC interface 'supervisor' initialized
2016-06-26 20:04:21,496 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2016-06-26 20:04:21,496 INFO supervisord started with pid 8
2016-06-26 20:04:22,499 INFO spawned: 'php-fpm7.0' with pid 11
2016-06-26 20:04:22,500 INFO spawned: 'apache2' with pid 12
2016-06-26 20:04:22,571 INFO exited: apache2 (exit status 0; not expected)
[26-Jun-2016 20:04:22] ERROR: Unable to create the PID file (/run/php/php7.0-fpm.pid).: No such file or directory (2)
[26-Jun-2016 20:04:22] ERROR: FPM initialization failed
2016-06-26 20:04:22,609 INFO exited: php-fpm7.0 (exit status 78; not expected)
2016-06-26 20:04:23,611 INFO spawned: 'php-fpm7.0' with pid 74
2016-06-26 20:04:23,613 INFO spawned: 'apache2' with pid 75
httpd (pid 16) already running
2016-06-26 20:04:23,669 INFO exited: apache2 (exit status 0; not expected)
[26-Jun-2016 20:04:23] ERROR: Unable to create the PID file (/run/php/php7.0-fpm.pid).: No such file or directory (2)
[26-Jun-2016 20:04:23] ERROR: FPM initialization failed
2016-06-26 20:04:23,694 INFO exited: php-fpm7.0 (exit status 78; not expected)
2016-06-26 20:04:25,698 INFO spawned: 'php-fpm7.0' with pid 79
2016-06-26 20:04:25,700 INFO spawned: 'apache2' with pid 80
httpd (pid 16) already running
2016-06-26 20:04:25,758 INFO exited: apache2 (exit status 0; not expected)
[26-Jun-2016 20:04:25] ERROR: Unable to create the PID file (/run/php/php7.0-fpm.pid).: No such file or directory (2)
[26-Jun-2016 20:04:25] ERROR: FPM initialization failed
2016-06-26 20:04:25,784 INFO exited: php-fpm7.0 (exit status 78; not expected)
2016-06-26 20:04:28,788 INFO spawned: 'php-fpm7.0' with pid 84
2016-06-26 20:04:28,789 INFO spawned: 'apache2' with pid 85
httpd (pid 16) already running
2016-06-26 20:04:28,847 INFO exited: apache2 (exit status 0; not expected)
2016-06-26 20:04:28,857 INFO gave up: apache2 entered FATAL state, too many start retries too quickly
[26-Jun-2016 20:04:28] ERROR: Unable to create the PID file (/run/php/php7.0-fpm.pid).: No such file or directory (2)
[26-Jun-2016 20:04:28] ERROR: FPM initialization failed
2016-06-26 20:04:28,872 INFO exited: php-fpm7.0 (exit status 78; not expected)
2016-06-26 20:04:29,873 INFO gave up: php-fpm7.0 entered FATAL state, too many start retries too quickly

and

from the nginx container

2016-06-26 11:19:02,307 CRIT Set uid to user 0
2016-06-26 11:19:02,320 INFO RPC interface 'supervisor' initialized
2016-06-26 11:19:02,320 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2016-06-26 11:19:02,321 INFO supervisord started with pid 14
2016-06-26 11:19:03,323 INFO spawned: 'php7.0-fpm' with pid 17
2016-06-26 11:19:03,324 INFO spawned: 'nginx' with pid 18
[26-Jun-2016 11:19:03] ERROR: unable to bind listening socket for address '/run/php/php7.0-fpm.sock': No such file or directory (2)
[26-Jun-2016 11:19:03] ERROR: FPM initialization failed
2016-06-26 11:19:03,406 INFO exited: php7.0-fpm (exit status 78; not expected)
2016-06-26 11:19:04,409 INFO spawned: 'php7.0-fpm' with pid 20
2016-06-26 11:19:04,409 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
[26-Jun-2016 11:19:04] ERROR: unable to bind listening socket for address '/run/php/php7.0-fpm.sock': No such file or directory (2)
[26-Jun-2016 11:19:04] ERROR: FPM initialization failed
2016-06-26 11:19:04,465 INFO exited: php7.0-fpm (exit status 78; not expected)
2016-06-26 11:19:06,470 INFO spawned: 'php7.0-fpm' with pid 21
[26-Jun-2016 11:19:06] ERROR: unable to bind listening socket for address '/run/php/php7.0-fpm.sock': No such file or directory (2)
[26-Jun-2016 11:19:06] ERROR: FPM initialization failed
2016-06-26 11:19:06,527 INFO exited: php7.0-fpm (exit status 78; not expected)
2016-06-26 11:19:09,532 INFO spawned: 'php7.0-fpm' with pid 30
[26-Jun-2016 11:19:09] ERROR: unable to bind listening socket for address '/run/php/php7.0-fpm.sock': No such file or directory (2)
[26-Jun-2016 11:19:09] ERROR: FPM initialization failed
2016-06-26 11:19:09,592 INFO exited: php7.0-fpm (exit status 78; not expected)
2016-06-26 11:19:10,594 INFO gave up: php7.0-fpm entered FATAL state, too many start retries too quickly
2016/06/26 11:19:13 [info] 19#19: *1 client closed connection while waiting for request, client: 192.168.99.1, server: 0.0.0.0:80

So my question is how do I correctly use supervisord to start php7.0-fpm/php-fpm7.0 in the docker containers.

Also understand that when I login into these containers and run this command then it starts to work! What am I doing wrong

service php7.0-fpm start

When I run the above command after fpm fails to start when container is ran, then it works. How do I do this with supervisord so I don't need to manually start with init.d


I see there is no /run/php/php7.0-fpm.pid file. This file is created when php7.0-fpm starts. So I solved this issue by adding to Dockerfile:

RUN service php7.0-fpm start

Of course after php-fpm installation :)


Creating the /var/run/php in the build i.e. mkdir -p /var/run/phpand then starting php-fpm in supervisord

[supervisord]
nodaemon=true

[program:php-fpm]
command=/usr/sbin/php-fpm7.0 -F
autostart=true
autorestart=unexpected
stdout_logfile=/var/log/php-fpm/stdout.log
stdout_logfile_maxbytes=0
stderr_logfile=/var/log/php-fpm/stderr.log
stderr_logfile_maxbytes=0
exitcodes=0

Also works.

If you copy paste the above make sure to also mkdir -p /var/log/php-fpm for supervisord to write log files to.