Reference article: https://www.cnblogs.com/boundless-sky/p/7182410.html
1. Download the image
docker pull nginx
docker pull php:7.2.4-fpm
2. Create an nginx configuration file: run a container, delete the container after copying 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. Prepare the environment
Copy the above default.conf to /home/wyt/docker_data/nginx, and then modify the content:
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. Test
put 2 test files index.html and test/index.php in /home/wyt/docker_data/www
6. Explain that
php:9000 in default.conf means to find php server in dns, and the following link is to put it in dns parsing