默认情况下,如何在 Docker 容器中启动 php-fpm? [英] How can I start php-fpm in a Docker container by default?

查看:107
本文介绍了默认情况下,如何在 Docker 容器中启动 php-fpm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 Docker 镜像 -

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"]

基本上,我想让 php-fpm 在 docker 容器启动时启动.如果我手动进入容器并使用 /usr/sbin/php-fpm 将其打开,则 php-fpm 可以正常工作.

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.

我用这个命令在我的 ansible 文件中尝试了它(它没有用).我也尝试使用服务模块,但没有成功.-

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

如何让 php-fpm 与 apache 一起运行?

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

推荐答案

你应该使用 supervisor 来启动几个服务

You should use supervisor in order to launch several services

在您的 dockerfile 中,安装 supervisor,然后启动

In your dockerfile, install supervisor, then you launch

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

并且您的 docker/supervisord.conf 包含您要启动的所有服务,因此您可以拥有类似的东西

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

当然你应该适应你的路径和 php-fpm 版本和你的服务(在我的例子中是 nginx,你的 apache 等等......),但基本上主管是从一个管理多个服务的启动的最佳方式起点.

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.

这里可以找到docker官方关于supervisor的文档

Here you can find the official doc of docker about supervisor

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

这篇关于默认情况下,如何在 Docker 容器中启动 php-fpm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆