7 Commits
1.1 ... master

Author SHA1 Message Date
df43e75dff #tradewind:add mysql8; add wsl support; add readme 2025-06-09 16:46:27 +08:00
4b5a861360 #tradewind:add php83 2023-12-25 18:23:07 +08:00
804eb5544f #tradewind:add php71 node 2023-07-19 11:06:25 +08:00
9f308af6b0 #tradewind:add gitignore 2022-11-16 15:23:27 +08:00
c29903b394 #tradewind:update 2022-11-16 15:21:20 +08:00
ddce943c33 #tradewind:update 2022-07-12 15:30:48 +08:00
4a4b03836d #tradewind:update 2021-07-30 11:37:01 +08:00
25 changed files with 10118 additions and 21 deletions

View File

@ -1 +1,2 @@
LOCAL_CODE_ROOT=/var/www/http LOCAL_CODE_ROOT=/Users/tradewind/Projects
PROJECT_PATH=/Users/tradewind/Projects/example

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.iml *.iml
log log
.env .env
.DS_Store

90
README.md Normal file
View File

@ -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/` 目录

12
docker-compose.wsl.yml Normal file
View File

@ -0,0 +1,12 @@
# docker-compose.wsl.ymlWSL 专用挂载)
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 特有挂载

View File

@ -6,7 +6,7 @@ services:
context: ./nginx/ context: ./nginx/
dockerfile: dockerfile dockerfile: dockerfile
ports: ports:
- 80:80 - "80:80"
networks: networks:
- server - server
volumes: volumes:
@ -16,18 +16,49 @@ services:
- ./log/nginx:/var/log/nginx - ./log/nginx:/var/log/nginx
container_name: nginx container_name: nginx
restart: always restart: always
php7.4: php71:
build:
context: ./php7.1/
dockerfile: dockerfile
# args:
# PROJECT_PATH: ${PROJECT_PATH:-/opt/project}
volumes:
- ./php7.1/sources.list:/etc/apt/sources.list
- ./php7.1/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./php7.1/php.ini:/usr/local/etc/php/php.ini
- ${LOCAL_CODE_ROOT}:/var/www/http
- ${PROJECT_PATH}:/opt/project # fix idea+python中xdebug项目路径
networks:
- server
container_name: php71
restart: always
php74:
build: build:
context: ./php7.4/ context: ./php7.4/
dockerfile: dockerfile dockerfile: dockerfile
# args:
# PROJECT_PATH: ${PROJECT_PATH:-/opt/project}
volumes: volumes:
- ./php7.4/sources.list:/etc/apt/sources.list - ./php7.4/sources.list:/etc/apt/sources.list
- ${LOCAL_CODE_ROOT}:/var/www/http - ./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
networks: networks:
- server - server
container_name: php74 container_name: php74
ports: restart: always
- 9000:9000 php83:
build:
context: ./php8.3/
dockerfile: dockerfile
volumes:
- ./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
networks:
- server
container_name: php83
restart: always restart: always
mysql: mysql:
build: build:
@ -41,8 +72,21 @@ services:
networks: networks:
- server - server
ports: ports:
- 3306:3306 - "3306:3306"
container_name: mysql 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: redis:
build: build:
context: ./redis/ context: ./redis/
@ -53,7 +97,30 @@ services:
# volumes: # volumes:
# - ${REDIS_DATA_PATH}:/data # - ${REDIS_DATA_PATH}:/data
ports: ports:
- 6379:6379 - "6379:6379"
container_name: redis container_name: redis
python:
build:
context: ./python/
dockerfile: dockerfile
volumes:
- ${LOCAL_CODE_ROOT}:/code
networks:
- server
container_name: python
ports:
- "8000:8000"
node:
build:
context: ./node/
dockerfile: dockerfile
volumes:
- ${LOCAL_CODE_ROOT}:/code
networks:
- server
stdin_open: true # docker run -i
tty: true # docker run -t
ipc: host
container_name: node
networks: networks:
server: server:

1
mysql8/dockerfile Normal file
View File

@ -0,0 +1 @@
FROM mysql:8.0

10
mysql8/sources.list Normal file
View File

@ -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

View File

@ -8,7 +8,7 @@ server {
} }
location ~ \.php$ { location ~ \.php$ {
fastcgi_pass php7.4:9000; fastcgi_pass php74:9000;
fastcgi_index index.php; fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

17
node/dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM node:latest
RUN apt-get update && apt-get install -y \
libgtkextra-dev \
libgconf2-dev \
libnss3 \
libasound2 \
libxtst-dev \
libxss1 \
libatk-bridge2.0-0 \
libgtk-3.0 \
libgbm-dev \
&& apt-get clean \
&& apt-get autoclean

View File

@ -0,0 +1,5 @@
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=PHPSTORM

48
php7.1/dockerfile Normal file
View File

@ -0,0 +1,48 @@
FROM php:7.1-fpm
#ARG PROJECT_PATH
#WORKDIR ${PROJECT_PATH}
WORKDIR /opt/project
RUN sed -i "s@http://deb.debian.org@http://mirrors.tencent.com@g" /etc/apt/sources.list
RUN apt-get update && apt-get install -y \
git \
zip \
unzip \
libpq-dev \
libzip-dev \
libpng-dev \
libfreetype6-dev \
libxml2-dev \
libicu-dev \
libjpeg62-turbo-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install -j$(nproc) \
bcmath \
pdo_mysql \
pdo_pgsql \
gd \
zip \
exif \
sockets \
intl \
soap \
pcntl \
&& pecl install \
redis \
xdebug-2.9.8 \
# mongodb \
&& docker-php-ext-enable \
redis \
xdebug \
# mongodb \
&& apt-get clean \
&& apt-get autoclean
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# 修改 composer 为国内镜像
RUN composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/

1947
php7.1/php.ini Normal file

File diff suppressed because it is too large Load Diff

10
php7.1/sources.list Normal file
View File

@ -0,0 +1,10 @@
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

View File

@ -0,0 +1,5 @@
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=PHPSTORM

View File

@ -3,6 +3,7 @@ FROM php:7.4-fpm
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.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 \ RUN apt-get update && apt-get install -y \
git \
zip \ zip \
unzip \ unzip \
libpq-dev \ libpq-dev \
@ -12,7 +13,10 @@ RUN apt-get update && apt-get install -y \
libxml2-dev \ libxml2-dev \
libicu-dev \ libicu-dev \
libjpeg62-turbo-dev \ libjpeg62-turbo-dev \
libssl-dev \
librdkafka-dev \
&& docker-php-ext-configure intl \ && docker-php-ext-configure intl \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install -j$(nproc) \ && docker-php-ext-install -j$(nproc) \
bcmath \ bcmath \
pdo_mysql \ pdo_mysql \
@ -23,12 +27,17 @@ RUN apt-get update && apt-get install -y \
sockets \ sockets \
intl \ intl \
soap \ soap \
pcntl \
&& pecl install \ && pecl install \
redis \ redis \
xdebug \ xdebug-3.1.6 \
mongodb-1.12.0 \
rdkafka-4.1.2 \
&& docker-php-ext-enable \ && docker-php-ext-enable \
redis \ redis \
xdebug \ xdebug \
mongodb \
rdkafka \
&& apt-get clean \ && apt-get clean \
&& apt-get autoclean && apt-get autoclean

1947
php7.4/php.ini Normal file

File diff suppressed because it is too large Load Diff

1947
php7.4/php.ini-dev Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
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 https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
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 https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

View File

@ -0,0 +1,5 @@
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=PHPSTORM

41
php8.3/dockerfile Normal file
View File

@ -0,0 +1,41 @@
FROM php:8.3-fpm
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 \
zip \
unzip \
libpq-dev \
libzip-dev \
libpng-dev \
libfreetype6-dev \
libxml2-dev \
libicu-dev \
libjpeg62-turbo-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install -j$(nproc) \
bcmath \
pdo_mysql \
pdo_pgsql \
gd \
zip \
exif \
sockets \
intl \
soap \
pcntl \
&& pecl install \
redis \
xdebug \
&& docker-php-ext-enable \
redis \
xdebug \
&& apt-get clean \
&& apt-get autoclean
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# 修改 composer 为国内镜像
RUN composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/

1947
php8.3/php.ini Normal file

File diff suppressed because it is too large Load Diff

1947
php8.3/php.ini-dev Normal file

File diff suppressed because it is too large Load Diff

10
php8.3/sources.list Normal file
View File

@ -0,0 +1,10 @@
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

24
python/dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM python:3.9-alpine3.13 as build
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& apk update \
&& apk add git gcc g++ musl-dev libffi-dev libressl-dev make
WORKDIR /install
COPY requirements.txt /install/requirements.txt
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /install/requirements.txt \
&& mkdir -p /install/lib/python3.9/site-packages \
&& cp -rp /usr/local/lib/python3.9/site-packages /install/lib/python3.9 \
&& cp -p /usr/local/bin/uvicorn /install/uvicorn
FROM python:3.9-alpine3.13
# This hack is widely applied to avoid python printing issues in docker containers.
# See: https://github.com/Docker-Hub-frolvlad/docker-alpine-python3/pull/13
ENV PYTHONUNBUFFERED=1
COPY --from=build /install/lib /usr/local/lib
COPY --from=build /install/uvicorn /usr/local/bin/uvicorn
WORKDIR /code
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

6
python/requirements.txt Normal file
View File

@ -0,0 +1,6 @@
fastapi
python-multipart
python_jose[cryptography]
SQLAlchemy[sqlite]
uvicorn[standard]
passlib[bcrypt]