1.先编写docker-compose.yml 文件
version: "2.1"
services:
nginx:
image: nginx #镜像
ports:
- "80:80"
volumes:
- ~./nginx/www:/usr/share/nginx/html
- ~./nginx/conf:/etc/nginx/conf.d
- ~./nginx/logs:/var/log/nginx
networks:
- lnmp-network
php:
image: php:7.3.33-fpm #镜像 具体版本
volumes:
- ~./nginx/www:/www
stdin_open: true
tty: true
networks:
- lnmp-network
mysql:
image: mysql:5.7.26
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD='123456'
networks:
- lnmp-network
networks:
lnmp-network:
2.创建好以下目录

image.png
3.配置php.conf

image.png
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm index.php;
location /
{
#ThinkPHP REWRITE支持
if (!-e $request_filename){
rewrite ^/(.*)$ /api.php?s=/$1 last;
rewrite ^/(.*)$ /index.php?s=/$1 last;
}
}
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;
}
}
输入命令
docker-compose up -d
成功后

image.png

image.png