一 下载centos镜像
docker pull centos
二 启动镜像
[root@Centos-node3 ~]# docker run -it --name my_ng centos bash
三 下载yum源安装nginx,php,supervisor
[root@7113a79455d1 yum.repos.d]# yum -y install nginx
[root@7113a79455d1 yum.repos.d]# yum install php-fpm -y
[root@7113a79455d1 yum.repos.d]# yum -y install supervisor -y
四 修改Ngix配置文件
vi /etc/nginx/nginx.conf
location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
# fastcgi_pass unix:/var/run/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
#编写index.php文件
[root@64d279ca2405 /]# vi /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
四 编写supervisor配置文件
[root@64d279ca2405 /]# vi /etc/supervisord.d/php_nginx.ini
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
[program:phpfpm]
command=/usr/sbin/php-fpm -F -c /etc/php.ini
autostart = true
startsecs =
autorestart = true
startretries =
user = root
redirect_stderr = false
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 20
[root@7113a79455d1 supervisord.d]# supervisord 启动
五 新开窗口打包镜像
[root@Centos-node3 ~]# docker commit -m "nginx 1.1 php 5.4" my_ng yanshicheng/testnginx:v1
sha256:4b9cc5c96908391b8d52c9938a50fedcf6f286f8be3ee1f2cc8d48534802e6d8
六 启动测试
docker run -it -p : --name ng yanshicheng/testnginx:v1 supervisord