|
|
@@ -1,35 +1,87 @@
|
|
|
-# https://docs.docker.com/compose/compose-file/05-services/
|
|
|
+# Docker Compose 配置文件
|
|
|
+# 参考文档: https://docs.docker.com/compose/compose-file/05-services/
|
|
|
+
|
|
|
services:
|
|
|
- # https://hub.docker.com/_/golang
|
|
|
+ # ==================== 开发环境服务 ====================
|
|
|
+ # Go 语言开发容器 - 用于代码编写、编译和调试
|
|
|
+ # 镜像参考: https://hub.docker.com/_/golang#shared-tags
|
|
|
go_kit:
|
|
|
+ # 使用官方 Go 1.26.2 镜像,包含完整的 Go 开发工具链
|
|
|
+ image: golang:1.26.2
|
|
|
+
|
|
|
+ # 端口映射: 将容器 22 端口映射到宿主机随机可用端口
|
|
|
ports:
|
|
|
- - 0:80
|
|
|
- 0:22
|
|
|
- image: golang:1.26.0
|
|
|
+
|
|
|
+ # 保持容器持续运行,便于 VS Code Dev Containers 连接
|
|
|
+ # sleep infinity 让容器无限期休眠,避免自动退出
|
|
|
command: sleep infinity
|
|
|
+
|
|
|
+ # 设置容器内的工作目录,所有命令在此目录下执行
|
|
|
working_dir: /workspace
|
|
|
+
|
|
|
+ # 卷挂载配置
|
|
|
volumes:
|
|
|
- - .:/workspace
|
|
|
+ # 持久化 bash 历史记录,方便命令历史检索
|
|
|
+ - dev-bash-history:/root/.bash_history
|
|
|
+
|
|
|
+ # 挂载本地 SSH 密钥,用于 Git 操作和远程连接
|
|
|
- ~/.ssh:/root/.ssh
|
|
|
+
|
|
|
+ # 将当前项目目录挂载到容器工作目录,实现代码实时同步
|
|
|
+ - .:/workspace
|
|
|
+
|
|
|
+ # 持久化 Go 模块缓存,加速依赖下载和构建
|
|
|
- go:/go
|
|
|
|
|
|
- gk_mysql:
|
|
|
+
|
|
|
+ # ==================== 数据库服务 ====================
|
|
|
+ # MySQL 8.0 数据库 - 用于应用数据存储
|
|
|
+ # 镜像参考: https://hub.docker.com/_/mysql
|
|
|
+ mysql:
|
|
|
+ # 使用 MySQL 8.0 Bookworm 版本,基于 Debian 12
|
|
|
+ image: mysql:8.0-bookworm
|
|
|
+
|
|
|
+ # 端口映射: 将容器 3306 端口映射到宿主机随机可用端口
|
|
|
ports:
|
|
|
- 0:3306
|
|
|
- image: mysql:8.0.37
|
|
|
+
|
|
|
+ # 自动重启策略: 除非手动停止,否则自动重启
|
|
|
+ # 确保数据库服务在异常退出后能够自动恢复
|
|
|
restart: unless-stopped
|
|
|
- # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
|
|
|
- # (this is just an example, not intended to be a production configuration)
|
|
|
- command: --default-authentication-plugin=mysql_native_password
|
|
|
+
|
|
|
+ # 环境变量配置: 设置 MySQL 根密码
|
|
|
environment:
|
|
|
MYSQL_ROOT_PASSWORD: root
|
|
|
|
|
|
- gk_redis:
|
|
|
+ # 启动命令: 设置 MySQL 认证插件为 mysql_native_password
|
|
|
+ # 兼容旧版应用的认证机制,避免连接问题
|
|
|
+ command: --default-authentication-plugin=mysql_native_password
|
|
|
+
|
|
|
+
|
|
|
+ # ==================== 缓存服务 ====================
|
|
|
+ # Redis 缓存服务 - 用于会话存储和缓存数据
|
|
|
+ # 镜像参考: https://hub.docker.com/_/redis
|
|
|
+ redis:
|
|
|
+ # 默认密码为空,生产环境请设置密码
|
|
|
+ # 使用 Redis 8.2.5 Bookworm 版本
|
|
|
+ image: redis:8.2.5-bookworm
|
|
|
+
|
|
|
+ # 端口映射: 将容器 6379 端口映射到宿主机随机可用端口
|
|
|
ports:
|
|
|
- 0:6379
|
|
|
- # 默认密码为空
|
|
|
- image: redis:7.2.5
|
|
|
|
|
|
+ # 自动重启策略: 除非手动停止,否则自动重启
|
|
|
+ # 确保 Redis 缓存服务在异常退出后能够自动恢复
|
|
|
+ restart: unless-stopped
|
|
|
+
|
|
|
+
|
|
|
+# ==================== 持久化卷定义 ====================
|
|
|
volumes:
|
|
|
- go:
|
|
|
- external: true
|
|
|
+ # 开发环境 bash 历史记录持久化卷
|
|
|
+ # 确保重启容器后命令历史不会丢失
|
|
|
+ dev-bash-history:
|
|
|
+
|
|
|
+ # Go 模块缓存持久化卷
|
|
|
+ # 加速依赖下载,避免重复下载第三方包
|
|
|
+ go:
|