commit 44f2310af1a1aa5ce070cf074da4aa1fe560cf25 Author: 王宏建 Date: Sun Apr 19 00:30:24 2026 +0800 feat(docker): 添加 Docker 配置文件和 Git 忽略规则 - 添加 .gitignore 文件以忽略 Docker 数据目录和日志文件 - 创建 MySQL Docker Compose 配置文件 - 创建 Nginx Docker Compose 配置文件 - 创建 Redis Docker Compose 配置文件 - 配置 MySQL 容器环境变量和数据卷 - 配置 Nginx 容器端口映射和配置卷 - 配置 Redis 容器持久化设置 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2973b16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Docker 数据目录 +mysql/data/* +!mysql/data/.gitkeep +redis/data/* +!redis/data/.gitkeep + +# Nginx 相关目录 +nginx/html/* +!nginx/html/.gitkeep +nginx/conf.d/* +!nginx/conf.d/.gitkeep +nginx/logs/* +!nginx/logs/.gitkeep + +# MySQL 初始化脚本目录 +mysql/init/* +!mysql/init/.gitkeep + +# 其他可能需要忽略的文件 +*.log +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/mysql/data/.gitkeep b/mysql/data/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/mysql/data/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/mysql/docker-compose.yml b/mysql/docker-compose.yml new file mode 100644 index 0000000..a3613f8 --- /dev/null +++ b/mysql/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' + +services: + mysql: + image: mysql:8.0 + container_name: mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_USER: docker + MYSQL_PASSWORD: docker + ports: + - "3306:3306" + volumes: + - ./data:/var/lib/mysql + - ./init:/docker-entrypoint-initdb.d diff --git a/mysql/init/.gitkeep b/mysql/init/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/mysql/init/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/nginx/conf.d/.gitkeep b/nginx/conf.d/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/nginx/conf.d/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/nginx/docker-compose.yml b/nginx/docker-compose.yml new file mode 100644 index 0000000..2adcc6d --- /dev/null +++ b/nginx/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.8' + +services: + nginx: + image: nginx:alpine + container_name: nginx + ports: + - "80:80" + - "443:443" + volumes: + - ./html:/usr/share/nginx/html + - ./conf.d:/etc/nginx/conf.d + - ./logs:/var/log/nginx diff --git a/nginx/html/.gitkeep b/nginx/html/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/nginx/html/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/nginx/logs/.gitkeep b/nginx/logs/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/nginx/logs/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/redis/data/.gitkeep b/redis/data/.gitkeep new file mode 100644 index 0000000..8e59abf --- /dev/null +++ b/redis/data/.gitkeep @@ -0,0 +1 @@ +# This file is used to keep the directory in Git even when it's empty diff --git a/redis/docker-compose.yml b/redis/docker-compose.yml new file mode 100644 index 0000000..d20bed2 --- /dev/null +++ b/redis/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + redis: + image: redis:7-alpine + container_name: redis + command: redis-server --appendonly yes + ports: + - "6379:6379" + volumes: + - ./data:/data