Skip to content
Advertisement

How can I start php-fpm in a Docker container by default?

I have this Docker image –

FROM centos:7
MAINTAINER Me <me.me>
RUN yum update -y
RUN yum install -y git https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

RUN yum install -y ansible
RUN git clone https://github.com/.../dockerAnsible.git
RUN ansible-playbook dockerFileBootstrap.yml
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); 
rm -f /lib/systemd/system/multi-user.target.wants/*;
rm -f /etc/systemd/system/*.wants/*;
rm -f /lib/systemd/system/local-fs.target.wants/*; 
rm -f /lib/systemd/system/sockets.target.wants/*udev*; 
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; 
rm -f /lib/systemd/system/basic.target.wants/*;
rm -f /lib/systemd/system/anaconda.target.wants/*;

VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 80 443 3306

CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

Basically, I want it so that php-fpm starts when the docker container starts. I have php-fpm working if I manually go into the container and turn it on with /usr/sbin/php-fpm.

I tried it inside of my ansible file with this command (it didn’t work). I tried using the service module as well with no luck.-

 - name: Start php fpm
   command: /usr/sbin/php-fpm

How can I have php-fpm running along with apache?

Advertisement

Answer

You should use supervisor in order to launch several services

In your dockerfile, install supervisor, then you launch

COPY ./docker/supervisord.conf /etc/supervisord.conf
....
CMD ["/usr/bin/supervisord", "-n"]

And your docker/supervisord.conf contains all the services you want to start, so you can have something like that

[program:php-fpm]
  command=/opt/remi/php70/root/usr/sbin/php-fpm -c /etc/php-fpm.conf
  ;command=/usr/sbin/php70-fpm -c /etc/php-fpm.d
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0

[program:nginx]
  command=/usr/sbin/nginx
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0

Of course you should adapt with your path and php-fpm versions and your services (nginx in my example, apache for you etc…), but basically supervisor is the best way to manage the start of several services from one start point.

Here you can find the official doc of docker about supervisor

https://docs.docker.com/engine/admin/using_supervisord/

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement