1.說明
該鏡像基于Alpine Linux v3.4內(nèi)核祷膳,安裝了Tengine version: Tengine/2.2.3(nginx version: nginx/1.8.1)和PHP 5.3.3 (cli),并通過supervisord進(jìn)程管理工具運(yùn)行tenginx和php兩個(gè)進(jìn)程,Dockerfile的ENTRYPOINT為
ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
備注:tengine為淘寶基于NGINX二次開發(fā),用法和NGINX一樣泣特,便于理解以下都以nginx說明。
2.nginx安裝信息
nginx安裝目錄:/usr/local/nginx;
nginx日志目錄:/usr/local/nginx/logs;
nginx配置文件目錄:/usr/local/nginx/conf;
nginx二進(jìn)制文件目錄:/usr/local/nginx/sbin;
nginx root根目錄:/usr/local/nginx/html;
nginx的server虛擬機(jī)配置文件存放目錄:/usr/local/nginx/conf/vhosts
3.PHP安裝信息
PHP編譯安裝
PHP安裝目錄:/usr/local/php;
PHP二進(jìn)制文件路徑:/usr/local/php/bin;
PHP配置文件路徑:/usr/local/php/etc;
PHP-FPM二進(jìn)制文件路徑:/usr/local/php/sbin;
3.supervisord進(jìn)程管理
注意:vim /etc/supervisord.conf
修改nodaemon=false為true 這樣Dockerfile文件的入口文件可以前臺(tái)運(yùn)行宅粥,一定注意0锱觥!尼酿!
[include]
files = supervisord.d/*.conf #默認(rèn)是配置文件的后綴是.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的內(nèi)容如下**:
[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的內(nèi)容如下**:
[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
使用鏡像創(chuàng)建容器:
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虛擬機(jī)的配置文件掛載到容器內(nèi)的/usr/local/nginx/conf/vhosts目錄下裳擎;
(2)/Users/php_code為本地目錄涎永,該目錄下的存放PHP代碼,該目錄下的PHP代碼被掛載到容器內(nèi)的/usr/local/nginx/html目錄下;
(3)NGINX虛擬機(jī)配置文件,nginx連接php-fpm的fastcgi_param配置信息寫了一個(gè)配置文件
在/usr/local/nginx/conf/php_fcgi.conf;scgi_param配置信息寫了一個(gè)
配置文件/usr/local/nginx/conf/scgi_params羡微,php-fpm的地址為127.0.0.1:9000谷饿,示例如下:
location ~\.php {
include php_fcgi.conf;
include pathinfo.conf;
}
需要注意的是:根據(jù)/Users/php_code內(nèi)目錄層級(jí)的不同,改寫nginx 虛擬機(jī)配置文件的root根目錄妈倔。
舉例:本地/users/php_code目錄下git clone的代碼倉庫wdwd博投,那么wdwd目錄被掛載到了容器內(nèi)部的/usr/local/nginx/html下,
即/usr/local/nginx/html/wdwd,PHP的入口文件路徑為/usr/local/nginx/html/wdwd/myshop/Public启涯,所以NGINX虛擬機(jī)
的root 改寫為/usr/local/nginx/html/wdwd/myshop/Public
5.Mac系統(tǒng)安裝Docker Desktop
docker下載鏈接
在mac上面使用Docker掛載目錄時(shí),需要先在Docker->Preference->Resources->FILE SHARING中添加該目錄恃轩,才能進(jìn)行掛載结洼!
默認(rèn)FILE SHARING中已添加了/Users目錄,如上把php_code目錄和nginx_vhosts目錄創(chuàng)建在/Users目錄下面叉跛,如果docker run運(yùn)行提示失敗松忍,則對(duì)該兩個(gè)目錄進(jìn)行添加。