转载至《Docker - Windows上搭建LNMP环境》
1 windows安装Docker Desktop
注:请仔细查看安装环境要求,否则容易做无用功
Hyper-v如果开启的话电脑有装VMware的话会VMware无法运行
附上 Hyper-v开启关闭命令,命令执行之后需要重启电脑生效。
1 bcdedit /set hypervisorlaunchtype off 关闭 2 bcdedit /set hypervisorlaunchtype auto 开启
2 下载镜像
1 docker pull nginx:latest 2 docker pull php:8.1-fpm 3 docker pull mysql:8.0 4 dokcer pull redis:latest
2.1 配置准备
我的宿主机文件配置:
1 # 存放容器配置文件夹 2 E:\docker\etc
etc里面的mysql、nginx、php分别存放相应的容器配置
nginx:
1 docker run --name tmp-nginx -d nginx 2 docker cp tmp-nginx:/etc/nginx E:\docker\etc\nginx 3 docker rm -f tmp-nginx
php:
1 docker run --name tmp-php-fpm -d php:8.1-fpm 2 docker cp tmp-php-fpm:/usr/local/etc E:\docker\etc\php 3 docker rm -f tmp-php-fpm
mysql:
1 cd E:\docker\etc 2 mkdir mysql 3 cd mysql 4 mkdir conf 5 mkdir logs 6 mkdir data
2.2 实例化容器
# 顺序:[因为前后有依赖【link】关系] mysql-->redis-->php-fpm-->nginx
mysql
1 docker run --name run-mysql-80 -p 33060:3306 -e 2 MYSQL_ROOT_PASSWORD=root 3 -v E:\docker\etc\mysql\conf:/etc/mysql/conf.d 4 -v E:\docker\etc\mysql\logs:/logs 5 -v E:\docker\etc\mysql\data:/var/lib/mysql -d mysql:8.0
redis
1 docker run --name run-redis-latest -p 6379:6379 -d redis:latest
php-fpm
1 docker run --name run-php-81-fpm 2 -v E:\project:/var/www/html 3 -v E:\docker\etc\php:/usr/local/etc 4 -v E:\docker\etc\php:/var/log/php -d php:8.1-fpm
nginx
1 docker run --name run-nginx-latest -p 8080:80 2 -v E:\project:/usr/share/nginx/html 3 -v E:\docker\etc\nginx:/etc/nginx 4 -v E:\docker\log\nginx:/var/log/nginx 5 --link run-php-81-fpm:php-fpm-container 6 --link run-redis-latest:redis 7 --link run-mysql-80:mysql -d nginx:latest
3 部署测试
编辑E:\docker\etc\nginx\conf.d路径下的default.conf文件
1 server { 2 listen 80; 3 listen [::]:80; 4 server_name localhost; 5 #access_log /var/log/nginx/host.access.log main; 6 7 location / { 8 root /usr/share/nginx/html/LaravelAdmin/public; 9 # 测试用的是Laravel如首页访问正常其他页面404,需加入如下配置 10 try_files $uri $uri/ /index.php?$query_string; 11 index index.php index.html index.htm; 12 } 13 14 #error_page 404 /404.html; 15 16 # redirect server error pages to the static page /50x.html 17 # 18 error_page 500 502 503 504 /50x.html; 19 location = /50x.html { 20 root /usr/share/nginx/html; 21 } 22 23 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 24 # 25 #location ~ \.php$ { 26 # proxy_pass http://127.0.0.1; 27 #} 28 29 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 30 # 31 location ~ \.php$ { 32 root html; 33 # link过来的容器名称php-fpm-container 34 fastcgi_pass php-fpm-container:9000; 35 fastcgi_index index.php; 36 # 此处配置 /var/www/html/LaravelAdmin/public 初始php容器时映射的目录是/var/www/html,不指定php容器无法解析目录会报错 37 # “2022/12/16 12:24:15 [error] 24#24: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.4:9000", host: "127.0.0.1:8080"” 38 # 问题参考《【Docker】FastCGI sent in stderr: "Primary script unknown" while reading》 39 fastcgi_param SCRIPT_FILENAME /var/www/html/LaravelAdmin/public$fastcgi_script_name; 40 include fastcgi_params; 41 } 42 43 # deny access to .htaccess files, if Apache's document root 44 # concurs with nginx's one 45 # 46 #location ~ /\.ht { 47 # deny all; 48 #} 49 }
访问
标签:run,etc,Windows,LNMP,nginx,mysql,docker,php,Docker From: https://www.cnblogs.com/chenjiangbin/p/16988491.html