mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-26 03:35:31 +00:00
Add blank lines around headers
This commit is contained in:
@@ -35,6 +35,7 @@ WORKDIR /app
|
||||
COPY --from=builder /app/main .
|
||||
CMD ["./main"]
|
||||
```
|
||||
|
||||
#### 2. GitLab CI 配置
|
||||
|
||||
GitLab CI(`.gitlab-ci.yml`)配置如下:
|
||||
@@ -74,6 +75,7 @@ deploy_staging:
|
||||
only:
|
||||
- develop
|
||||
```
|
||||
|
||||
### 21.1.3 最佳实践
|
||||
|
||||
1. **不可变基础设施**:一旦镜像构建完成,在各个环境(Dev、Staging、Prod)中都应该使用同一个镜像 tag(通常是 commit hash),而不是重新构建。
|
||||
|
||||
@@ -46,6 +46,7 @@ jobs:
|
||||
with:
|
||||
args: go version
|
||||
```
|
||||
|
||||
## 21.2.3 参考资料
|
||||
|
||||
* [Actions Docs](https://docs.github.com/en/actions)
|
||||
|
||||
@@ -70,6 +70,7 @@ trigger:
|
||||
├── .drone.yml
|
||||
└── app.go
|
||||
```
|
||||
|
||||
## 21.3.3 推送项目源代码到 GitHub
|
||||
|
||||
```bash
|
||||
@@ -79,6 +80,7 @@ git commit -m "test drone ci"
|
||||
|
||||
git push origin master
|
||||
```
|
||||
|
||||
## 21.3.4 查看项目构建过程及结果
|
||||
|
||||
打开我们部署好的 `Drone` 网站或者 Drone Cloud,即可看到构建结果。
|
||||
|
||||
@@ -39,6 +39,7 @@ VS Code 会拉取镜像并启动容器,随后你就可以在容器内运行:
|
||||
```bash
|
||||
go test ./...
|
||||
```
|
||||
|
||||
## 21.6.3 结合 Docker Compose(可选)
|
||||
|
||||
如果项目同时依赖数据库/缓存(例如 Postgres/Redis),可以使用 `dockerComposeFile`
|
||||
|
||||
@@ -120,6 +120,7 @@ require (
|
||||
// 如果需要依赖
|
||||
)
|
||||
```
|
||||
|
||||
#### 带依赖的 Go 应用
|
||||
|
||||
**应用代码(使用 Gin 框架):**
|
||||
@@ -182,6 +183,7 @@ EXPOSE 8080
|
||||
|
||||
CMD ["./app"]
|
||||
```
|
||||
|
||||
### 21.7.2 Rust 应用的最小化镜像构建
|
||||
|
||||
Rust 因其性能和安全性在系统级应用中备受青睐。
|
||||
@@ -273,6 +275,7 @@ curl http://localhost:8080/health | jq .
|
||||
# Rust 应用通常比 Go 更小:5-20MB(取决于依赖)
|
||||
docker images rust-app
|
||||
```
|
||||
|
||||
### 21.7.3 数据库容器化最佳实践
|
||||
|
||||
#### PostgreSQL 生产部署
|
||||
@@ -455,6 +458,7 @@ services:
|
||||
volumes:
|
||||
postgres_data:
|
||||
```
|
||||
|
||||
#### MySQL/MariaDB 部署
|
||||
|
||||
```dockerfile
|
||||
@@ -495,6 +499,7 @@ server_id = 1
|
||||
log_bin = mysql-bin
|
||||
binlog_format = ROW
|
||||
```
|
||||
|
||||
#### Redis 缓存部署
|
||||
|
||||
```dockerfile
|
||||
@@ -545,6 +550,7 @@ client-output-buffer-limit normal 0 0 0
|
||||
client-output-buffer-limit slave 256mb 64mb 60
|
||||
client-output-buffer-limit pubsub 32mb 8mb 60
|
||||
```
|
||||
|
||||
### 21.7.4 微服务架构的 Docker Compose 编排
|
||||
|
||||
**三层微服务架构示例:**
|
||||
@@ -736,6 +742,7 @@ server {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 21.7.5 使用 VS Code Dev Containers
|
||||
|
||||
Dev Containers 让整个开发环境容器化,提升团队一致性。
|
||||
|
||||
Reference in New Issue
Block a user