下载PHP镜像
docker pull php:5.6-fpm
下载Nginx镜像
docker pull nginx:latest
运行PHP容器
docker run --name myphp-fpm -v ~/nginx/www:/www -d php:5.6-fpm
创建文件及文件夹
cd %USERPROFILE%
md nginx\conf\conf.d
md nginx\www
在用户目录下添加/nginx/conf/conf.d/runoob-test-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 php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
在用户目录下添加/nginx/www/test.php 文件,内容如下:
<?php
echo phpinfo();
?>
运行Nginx容器
docker run --name runoob-php-nginx -p 8083:80 -d -v ~/nginx/www:/usr/share/nginx/html:ro -v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro --link myphp-fpm:php nginx
测试结果