下载
[root@localhost www]# docker pull php:5.6-fpm
[root@localhost test]# docker images php
REPOSITORY TAG IMAGE ID CREATED SIZE
php latest 56de6f634956 7 days ago 400MB
php 5.6-fpm 3458979c7744 6 months ago 344MB
第一个是之前安装的,略过
启动
[root@localhost test]# docker run --name myphp-fpm -v /test/www:/www -d php:5.6-fpm
f4cebdf34df12e40319822a152e1ad232f61c56f2eb2fa50dc457bb6b9b29d39
使用nginx+php进行测试,看是否能访问php文件。
[root@localhost conf]# pwd
/test/conf
[root@localhost conf]# mkdir conf.d
新建hbk_php.conf
[root@localhost conf.d]# cat hbk_php.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass hbk:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
增加hbk域名
[root@localhost test]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 test11g
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.8.194 hello.com
127.0.0.1 hello.com
127.0.0.1 hbk
启动
[root@localhost test]# docker run --name php-nginx-hbk -p 9999:80 -v /test/www/:/usr/share/nginx/html:ro -v /test/conf/conf.d:/etc/nginx/conf.d:ro --link myphp-fpm:hbk -d nginx
9b021daa8309b23689d695063dfbf14572093ee0296eba2518a49b9acb486653
解释
–link myphp-fpm:php: 把 myphp-fpm 的网络并入 nginx,并通过修改 nginx 的 /etc/hosts,把域名 hbk映射成 127.0.0.1,让 nginx 通过 hbk:9000 访问 php-fpm
ro表示只读
在www目录下新建index.php文件
<?php
echo phpinfo();
?>
浏览器访问如下: