docker-php镜像包含nginx和php5.3.3

1.说明

该镜像基于Alpine Linux v3.4内核,安装了Tengine version: Tengine/2.2.3(nginx version: nginx/1.8.1)和PHP 5.3.3 (cli),并通过supervisord进程管理工具运行tenginx和php两个进程,Dockerfile的ENTRYPOINT为
ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
备注:tengine为淘宝基于NGINX二次开发,用法和NGINX一样,便于理解以下都以nginx说明。

2.nginx安装信息

nginx安装目录:/usr/local/nginx;
nginx日志目录:/usr/local/nginx/logs;
nginx配置文件目录:/usr/local/nginx/conf;
nginx二进制文件目录:/usr/local/nginx/sbin;
nginx root根目录:/usr/local/nginx/html;
nginx的server虚拟机配置文件存放目录:/usr/local/nginx/conf/vhosts

3.PHP安装信息

PHP编译安装
PHP安装目录:/usr/local/php;
PHP二进制文件路径:/usr/local/php/bin;
PHP配置文件路径:/usr/local/php/etc;
PHP-FPM二进制文件路径:/usr/local/php/sbin;

3.supervisord进程管理

注意:vim /etc/supervisord.conf
修改nodaemon=false为true 这样Dockerfile文件的入口文件可以前台运行,一定注意!!!
[include]
files = supervisord.d/*.conf #默认是配置文件的后缀是.ini,这里修改为.conf

NGINX和PHP的supervisord配置文件路径:/etc/supervisord.d
[root@9d0312f299f6 supervisord.d]# pwd
/etc/supervisord.d
[root@9d0312f299f6 supervisord.d]# ll
total 8
-rw-r--r-- 1 root root 1841 Apr 22 10:55 nginx.conf
-rw-r--r-- 1 root root 1853 Apr 22 10:44 php-fpm.conf

**nginx.conf的内容如下**:
[program:nginx]
command=/usr/local/nginx/sbin/nginx -g "daemon off;"
autostart=true                ; start at supervisord start (default: true)
autorestart=true             ; whether/when to restart (default: unexpected)
startretries=5             ; max # of serial start failures (default 3)
exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
stopasgroup=false             ; send stop signal to the UNIX process group (default false)
killasgroup=false             ; SIGKILL the UNIX process group (def false)
user=root                  ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/usr/local/nginx/logs/access.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=2048MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=2     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false   ; emit events on stdout writes (default false)
stderr_logfile=/usr/local/nginx/logs/error.log  ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=2048MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=2     ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false   ; emit events on stderr writes (default false)i
environment=GOGCTRACE=1       ; process environment additions (def no adds)

**php-fpm.conf的内容如下**:
[program:php-fpm]
command=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf   ; the program (relative uses PATH, can take args)
autostart=true                ; start at supervisord start (default: true)
autorestart=true              ; whether/when to restart (default: unexpected)
startretries=5                ; max # of serial start failures (default 3)
exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
stopasgroup=false             ; send stop signal to the UNIX process group (default false)
killasgroup=false             ; SIGKILL the UNIX process group (def false)
user=root                  ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/usr/local/php/var/log/php-fpm.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=2048MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=2     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false   ; emit events on stdout writes (default false)
stderr_logfile=/usr/local/php/var/log/php-fpm-error.log  ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=2048MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=2     ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false   ; emit events on stderr writes (default false)i
environment=GOGCTRACE=1       ; process environment additions (def no adds)

4.镜像使用

拉取镜像:docker pull liujiabao/php:v2.1
使用镜像创建容器:
docker run -itd -v /Users/php_code:/usr/local/nginx/html  -v /Users/nginx_vhosts:/usr/local/nginx/conf/vhosts -p 80:80 liujiabao/php_5.3.3:v1.4

说明:
(1)/Users/nginx_vhosts为本地目录,该目录下的nginx server虚拟机的配置文件挂载到容器内的/usr/local/nginx/conf/vhosts目录下;
(2)/Users/php_code为本地目录,该目录下的存放PHP代码,该目录下的PHP代码被挂载到容器内的/usr/local/nginx/html目录下;
(3)NGINX虚拟机配置文件,nginx连接php-fpm的fastcgi_param配置信息写了一个配置文件
在/usr/local/nginx/conf/php_fcgi.conf;scgi_param配置信息写了一个
配置文件/usr/local/nginx/conf/scgi_params,php-fpm的地址为127.0.0.1:9000,示例如下:
    location ~\.php {
        include        php_fcgi.conf;
        include        pathinfo.conf;
    }

需要注意的是:根据/Users/php_code内目录层级的不同,改写nginx 虚拟机配置文件的root根目录。
举例:本地/users/php_code目录下git clone的代码仓库wdwd,那么wdwd目录被挂载到了容器内部的/usr/local/nginx/html下,
即/usr/local/nginx/html/wdwd,PHP的入口文件路径为/usr/local/nginx/html/wdwd/myshop/Public,所以NGINX虚拟机
的root 改写为/usr/local/nginx/html/wdwd/myshop/Public

5.Mac系统安装Docker Desktop

docker下载链接
在mac上面使用Docker挂载目录时,需要先在Docker->Preference->Resources->FILE SHARING中添加该目录,才能进行挂载!
默认FILE SHARING中已添加了/Users目录,如上把php_code目录和nginx_vhosts目录创建在/Users目录下面,如果docker run运行提示失败,则对该两个目录进行添加。

你可能感兴趣的:(docker-php镜像包含nginx和php5.3.3)