- docker run --name nginx -p 8898:80 -d nginx:1.20.2-alpine
-
- # 将容器nginx.conf文件复制到宿主机
- docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
-
- # 将容器conf.d文件夹下内容复制到宿主机
- docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/conf.d
-
- # 将容器中的html文件夹复制到宿主机
- docker cp nginx:/usr/share/nginx/html /usr/local/nginx/
搭建php-fpm
docker container run -d --name php-fpm -v /usr/local/nginx/html:/var/www/html php:7.4.27-fpm-alpine
删除nginx原容器,新建映射路径
docker container run -d --name nginx -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d -v /usr/local/nginx/log:/var/log/nginx -v /usr/local/nginx/html:/usr/share/nginx/html --link php-fpm:php-fpm -p 8898:80 nginx:1.20.2-alpine
新增测试文件
- cd /usr/local/nginx/html
-
- vim a.php
- ---------------
- phpinfo(); ?>
- ---------------
-
-
- vim b.php
- ---------------
- echo time(); ?>
- ---------------
- location ~ \.php$ {
- root /var/www/html;
- fastcgi_pass php-fpm:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
测试