我将php和nginx一起封在了一个docker里,如何让nginx和php自启动?

查看:629
本文介绍了我将php和nginx一起封在了一个docker里,如何让nginx和php自启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我每次新建一个容器时,都要进入容器里面,启动nginx和php,请问如何每次新建容器时都让nginx和php自启动?

解决方案

你可以使用supervisord来管理

  1. 先进入容器安装supervisord,(安装过程网上搜下)

推荐将主配置文件放在:/etc/supervisord.conf vim /etc/supervisord.conf

[unix_http_server]
file=/var/run/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisord]
nodaemon=true

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = /etc/supervisor/conf.d/*.conf

然后在/etc/supervisor/conf.d/添加php和nginx的启动命令

例如添加nginx, vim /etc/supervisor/conf.d/nginx_super.conf

[program:nginx]
command=nginx

  1. 然后提交一个新的镜像出来,例如

docker commit -a "qclaogui" -m "bulabula" nginx-php:commit

  1. 编写新的Dokcerfile

FROM nginx-php:commit

MAINTAINER xxx@xxx.com

EXPOSE 80 443

ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]

  1. 重新构建一个镜像

docker build -t nginx-php:v1 .

  1. 基于新构建的镜像运行容器

docker run --name test-nginx-php -p 8081:80 -d nginx-php:v1注意这里用的是-d参数

根据你的情况,大致解决思路是这个样子,可以参考一下

这篇关于我将php和nginx一起封在了一个docker里,如何让nginx和php自启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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