From df43e75dffb6d620cbbc2a9d67d820a80c4a05c8 Mon Sep 17 00:00:00 2001 From: wanwenshan Date: Mon, 9 Jun 2025 16:46:27 +0800 Subject: [PATCH] #tradewind:add mysql8; add wsl support; add readme --- README.md | 90 +++++++++++++++++++++++++++++++++++++++ docker-compose.wsl.yml | 12 ++++++ docker-compose.yml | 17 +++++++- mysql8/dockerfile | 1 + mysql8/sources.list | 10 +++++ nginx/conf.d/example.conf | 2 +- php7.4/dockerfile | 14 +++--- php8.3/dockerfile | 4 +- 8 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 README.md create mode 100644 docker-compose.wsl.yml create mode 100644 mysql8/dockerfile create mode 100644 mysql8/sources.list diff --git a/README.md b/README.md new file mode 100644 index 0000000..42c2fbb --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# PHP Docker 开发环境 + +一个完整的PHP开发环境,包含多版本PHP、数据库、缓存等服务。 + +## 服务列表 + +| 服务 | 端口 | 版本 | 说明 | +|------|------|------|------| +| Nginx | 80 | latest | Web服务器 | +| PHP 7.1 | 9000 | 7.1 | PHP-FPM | +| PHP 7.4 | 9000 | 7.4 | PHP-FPM | +| PHP 8.3 | 9000 | 8.3 | PHP-FPM | +| MySQL | 3306 | 5.7 | 数据库 | +| MySQL8 | 3306 | 8.0 | 数据库 | +| Redis | 6379 | latest | 缓存 | +| Python | 8000 | latest | Python环境 | +| Node.js | - | latest | Node.js环境 | + +## 快速开始 + +### 1. 环境变量配置 +创建 `.env` 文件并设置以下变量: +```bash +LOCAL_CODE_ROOT=/path/to/your/code # 本地代码目录 +PROJECT_PATH=/path/to/your/project # 项目路径 +``` + +### 2. 启动服务 + +**普通环境:** +```bash +docker-compose up -d +``` + +**WSL环境:** +```bash +docker-compose -f docker-compose.yml -f docker-compose.wsl.yml up -d +``` + +### 3. 验证服务 +```bash +docker-compose ps +``` + +## 使用说明 + +### Nginx配置 +- 配置文件位置:`./nginx/conf.d/` +- 参考示例:`./nginx/conf.d/example.conf` +- 网站根目录:`/var/www/http` + +### PHP版本切换 +在Nginx配置中修改 `fastcgi_pass` 参数: +- PHP 7.1:`fastcgi_pass php71:9000;` +- PHP 7.4:`fastcgi_pass php74:9000;` +- PHP 8.3:`fastcgi_pass php83:9000;` + +### 数据库连接 +- **MySQL 5.7**:`mysql:3306`,用户名/密码:`root/root` +- **MySQL 8.0**:`mysql8:3306`,用户名/密码:`root/root` +- **Redis**:`redis:6379` + +### 常用命令 + +**查看日志:** +```bash +docker-compose logs -f [服务名] +``` + +**进入容器:** +```bash +docker exec -it [容器名] bash +``` + +**重启服务:** +```bash +docker-compose restart [服务名] +``` + +**停止所有服务:** +```bash +docker-compose down +``` + +## 注意事项 + +1. 确保本地80、3306、6379端口未被占用 +2. WSL环境需要额外的挂载配置 +3. Xdebug已预配置,端口9003 +4. 日志文件保存在 `./log/` 目录 diff --git a/docker-compose.wsl.yml b/docker-compose.wsl.yml new file mode 100644 index 0000000..549201d --- /dev/null +++ b/docker-compose.wsl.yml @@ -0,0 +1,12 @@ +# docker-compose.wsl.yml(WSL 专用挂载) +version: '3.8' +services: + php71: + volumes: + - /mnt/d:/mnt/d # WSL 特有挂载 + php74: + volumes: + - /mnt/d:/mnt/d # WSL 特有挂载 + php83: + volumes: + - /mnt/d:/mnt/d # WSL 特有挂载 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 03b4472..5b5657e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,7 +42,7 @@ services: - ./php7.4/sources.list:/etc/apt/sources.list - ./php7.4/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - ./php7.4/php.ini:/usr/local/etc/php/php.ini - - ${LOCAL_CODE_ROOT}:/var/www/http + - ${LOCAL_CODE_ROOT}:/var/www networks: - server container_name: php74 @@ -55,7 +55,7 @@ services: - ./php8.3/sources.list:/etc/apt/sources.list - ./php8.3/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - ./php8.3/php.ini:/usr/local/etc/php/php.ini - - ${LOCAL_CODE_ROOT}:/var/www/http + - ${LOCAL_CODE_ROOT}:/var/www networks: - server container_name: php83 @@ -74,6 +74,19 @@ services: ports: - "3306:3306" container_name: mysql + mysql8: + build: + context: mysql8/ + dockerfile: dockerfile + restart: always + environment: + MYSQL_ROOT_PASSWORD: root + command: --default-authentication-plugin=mysql_native_password + networks: + - server + ports: + - "3306:3306" + container_name: mysql8 redis: build: context: ./redis/ diff --git a/mysql8/dockerfile b/mysql8/dockerfile new file mode 100644 index 0000000..7197596 --- /dev/null +++ b/mysql8/dockerfile @@ -0,0 +1 @@ +FROM mysql:8.0 diff --git a/mysql8/sources.list b/mysql8/sources.list new file mode 100644 index 0000000..8fbb4a9 --- /dev/null +++ b/mysql8/sources.list @@ -0,0 +1,10 @@ +deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \ No newline at end of file diff --git a/nginx/conf.d/example.conf b/nginx/conf.d/example.conf index 7187ce1..93c67e0 100644 --- a/nginx/conf.d/example.conf +++ b/nginx/conf.d/example.conf @@ -8,7 +8,7 @@ server { } location ~ \.php$ { - fastcgi_pass php71:9000; + fastcgi_pass php74:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/php7.4/dockerfile b/php7.4/dockerfile index 4dcd098..f5d3469 100644 --- a/php7.4/dockerfile +++ b/php7.4/dockerfile @@ -1,10 +1,6 @@ FROM php:7.4-fpm -ARG PROJECT_PATH - -WORKDIR ${PROJECT_PATH} - -RUN sed -i "s@http://deb.debian.org@http://mirrors.tencent.com@g" /etc/apt/sources.list +RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list RUN apt-get update && apt-get install -y \ git \ @@ -17,6 +13,8 @@ RUN apt-get update && apt-get install -y \ libxml2-dev \ libicu-dev \ libjpeg62-turbo-dev \ + libssl-dev \ + librdkafka-dev \ && docker-php-ext-configure intl \ && docker-php-ext-configure pcntl --enable-pcntl \ && docker-php-ext-install -j$(nproc) \ @@ -33,11 +31,13 @@ RUN apt-get update && apt-get install -y \ && pecl install \ redis \ xdebug-3.1.6 \ -# mongodb \ + mongodb-1.12.0 \ + rdkafka-4.1.2 \ && docker-php-ext-enable \ redis \ xdebug \ -# mongodb \ + mongodb \ + rdkafka \ && apt-get clean \ && apt-get autoclean diff --git a/php8.3/dockerfile b/php8.3/dockerfile index c6b9358..bfa01b2 100644 --- a/php8.3/dockerfile +++ b/php8.3/dockerfile @@ -1,8 +1,6 @@ FROM php:8.3-fpm -ARG PROJECT_PATH - -WORKDIR ${PROJECT_PATH} +RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/debian.sources RUN apt-get update && apt-get install -y \ git \