参考文章:https://www.cnblogs.com/boundless-sky/p/7182410.html
1.下载镜像
docker pull nginx
docker pull php:7.2.4-fpm
2.搞个nginx的配置文件:运行一个容器,拷完default.conf后删除这个容器
docker run --name mynginx_test -d -p 28369:80 nginx
docker cp mynginx_test:/etc/nginx/conf.d/default.conf ./default.conf
docker stop mynginx_test
docker rm mynginx_test
3.准备环境
把上面的default.conf拷贝到/home/wyt/docker_data/nginx,然后修改内容:
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ .php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
准备/home/wyt/docker_data/www存放网页
4.运行容器
docker run --name myphp -d -v /home/wyt/docker_data/www:/var/www/html php:7.2.4-fpm
docker run --name mynginx -d -p 80:80 -v /home/wyt/docker_data/www:/usr/share/nginx/html
-v /home/wyt/docker_data/nginx:/etc/nginx/conf.d --link myphp:php nginx
5.测试
在/home/wyt/docker_data/www放2个测试文件index.html和test/index.php
6.说明
default.conf里面php:9000的意思是在dns里面找php服务器,而后面的link就是把它放到dns解析