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运行提示失败,则对该两个目录进行添加。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269