# docker **Repository Path**: hansn/docker ## Basic Information - **Project Name**: docker - **Description**: 利用docker意见部署本地集成环境 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-08-07 - **Last Updated**: 2025-08-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 一键部署本地开发环境 ## 环境要求 - Windows 11 (WSL已开启) - Docker Desktop - Git - PowerShell ## 下载以及配置 打开PowerShell执行以下命令 ```Powershell C:\Users\jiang> D: D:\> git clone https://gitee.com/hansn/docker.git Cloning into 'docker'... remote: Enumerating objects: 12, done. remote: Counting objects: 100% (12/12), done. remote: Compressing objects: 100% (7/7), done. remote: Total 12 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) Receiving objects: 100% (12/12), 37.92 KiB | 12.64 MiB/s, done. D:\> cd D:/docker D:\docker [master ≡]> docker compose up -d [+] Running 6/6 ✔ Network webservices_web Created ✔ Container redis7.0.12 Started ✔ Container rabbitmq4 Started ✔ Container php8.4 Started ✔ Container mysql8.0 Started ✔ Container nginx Started ✔ Container php7.4 Started D:\docker [master ≡]> ``` ## 访问 在浏览器输入[http://localhost/index.php](http://localhost/index.php) ## 构建和删除容器组 ``` # 构建容器 docker compose up -d # 删除容器 docker compose down ``` ## 说明 | 容器名 | 容器IP | 密码 | 外部访问地址 | 配置说明 | | --------- | ------------- | ------------------- | ---------------------------------- | -------------------------- | | nginx | 172.172.0.2 | | `localhost` | 站点配置文件目录 `conf.d/` | | mysql | 172.172.0.100 | root密码为`root123` | `localhost:3306` | | | php7.4 | 172.172.0.74 | | | | | php8.4 | 172.172.0.84 | | | | | redis | 172.172.0.120 | foobared | `localhost:6379` | | | rabbitmq4 | 172.172.0.140 | | `localhost:5672`/`localhost:15672` | | > 特别说明:容器IP地址只能加入名为`web`的容器才能访问 更多用法请查看`compose.yaml`文件 ## 路径说明 ``` docker │ compose.yaml │ LICENSE │ README.md │ redis.conf # redis配置文件,可自行配置 │ ├─conf.d # nginx配置目录,可根据自己需求新增和修改配置文件 │ localhost.conf # nginx配置示例 │ ├─Dockfiles # 容器的Dockerfiles文件目录(包含构建所需要的文件) │ debian.sources │ libzip-1.9.2.tar.gz │ php7-4.Dockerfile # php8.4的Dockerfile文件 │ php8-4.Dockerfile # php7.4的Dockerfile文件 │ redis-6.2.0.tgz │ sources.list │ └─code # 代码所放置的目录 ├─html └─localhost # localhost.conf指向的项目 index.php ``` ## 开始使用(以Laravel为例) 以laravel为例,参考官方文档[https://laravel.com/docs/12.x](https://laravel.com/docs/12.x) 1、在`code`下执行`laravel new example-app` 2、新增nginx配置文件`conf.d/example-app.conf`(参考地址[https://laravel.com/docs/12.x/deployment#nginx](https://laravel.com/docs/12.x/deployment#nginx)),内容如下, ```conf server { listen 80; listen [::]:80; server_name example.com; # 此处修改 root /var/www/example-app/public; # 此处修改 add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ ^/index\.php(/|$) { fastcgi_pass 172.172.0.84:9000; # 此处修改 fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; fastcgi_hide_header X-Powered-By; } location ~ /\.(?!well-known).* { deny all; } } ``` 3、在本机hosts文件新增域名(路径为`C:\Windows\System32\drivers\etc`), ```hosts # 新增该行 127.0.0.1 example.com ``` 4、设置项目的`.env` ``` # 设置MySQL这几项 DB_CONNECTION=mysql DB_HOST=172.172.0.100 DB_PORT=3306 DB_DATABASE=example_app DB_USERNAME=root DB_PASSWORD=root123 # 设置Redis REDIS_HOST=172.172.0.120 REDIS_PASSWORD=foobared ``` 5、创建项目的数据库 利用navicat等数据库管理工具,连接数据库【主机:localhost,用户名:root,密码:root123】, 新建数据库`example_app` 6、执行数据库迁移操作 可以通过Docker Desktop或者命令行进入,此处以命令行为例 ```powershell C:\Users\jiang> D: D:\> docker exec -it php8.4 bash root@beba3180acd3:/var/www/html# cd /var/www/example-app/ root@beba3180acd3:/var/www/example-app# php artisan migrate INFO Preparing database. Creating migration table .................................... 76.96ms DONE INFO Running migrations. 0001_01_01_000000_create_users_table ....................... 194.59ms DONE 0001_01_01_000001_create_cache_table ........................ 58.62ms DONE 0001_01_01_000002_create_jobs_table ........................ 157.80ms DONE root@beba3180acd3:/var/www/example-app# ``` 7、重启nginx容器 `docker container restart nginx` 8、打开浏览器访问[http://example.com/](http://example.com/)