Remove blank lines after code block markers

This commit is contained in:
yeasy
2026-03-21 22:36:09 -07:00
parent 312f8fea42
commit 9ac19d79ee
132 changed files with 0 additions and 1517 deletions

View File

@@ -44,11 +44,9 @@ func main() {
}
}
```
**多阶段 Dockerfile**
```dockerfile
# Stage 1: 构建阶段
FROM golang:1.20-alpine AS builder
@@ -88,11 +86,9 @@ EXPOSE 8080
# 使用绝对路径作为 ENTRYPOINT
ENTRYPOINT ["/app"]
```
**构建和测试**
```bash
# 构建镜像
docker build -t go-app:latest .
@@ -113,7 +109,6 @@ docker exec go-demo ls -la /
# 镜像大小通常 < 10MB相比 golang:1.20-alpine 的 ~1GB
docker history go-app:latest
```
**go.mod go.sum 示例**
```text
@@ -125,7 +120,6 @@ require (
// 如果需要依赖
)
```
#### 带依赖的 Go 应用
**应用代码使用 Gin 框架**
@@ -156,7 +150,6 @@ func main() {
log.Fatal(router.Run(":8080"))
}
```
**优化的 Dockerfile**
```dockerfile
@@ -189,7 +182,6 @@ EXPOSE 8080
CMD ["./app"]
```
### 21.7.2 Rust 应用的最小化镜像构建
Rust 因其性能和安全性在系统级应用中备受青睐
@@ -226,7 +218,6 @@ async fn hello() -> HttpResponse {
}))
}
```
**Cargo.toml**
```toml
@@ -245,11 +236,9 @@ tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
```
**多阶段构建 Dockerfile**
```dockerfile
# Stage 1: 编译
FROM rust:1.75-alpine AS builder
@@ -274,7 +263,6 @@ EXPOSE 8080
CMD ["/app"]
```
**构建和验证**
```bash
@@ -285,7 +273,6 @@ curl http://localhost:8080/health | jq .
# Rust 应用通常比 Go 更小5-20MB取决于依赖
docker images rust-app
```
### 21.7.3 数据库容器化最佳实践
#### PostgreSQL 生产部署
@@ -312,7 +299,6 @@ HEALTHCHECK --interval=10s --timeout=5s --start-period=40s --retries=3 \
EXPOSE 5432
```
**初始化脚本init-db.sql**
```sql
@@ -348,7 +334,6 @@ GRANT USAGE ON SCHEMA public TO appuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO appuser;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO appuser;
```
**健康检查脚本health-check.sh**
```bash
@@ -362,7 +347,6 @@ PGPASSWORD=$POSTGRES_PASSWORD pg_isready \
exit $?
```
**Docker Compose 配置**
```yaml
@@ -419,7 +403,6 @@ networks:
backend:
driver: bridge
```
**性能优化配置**
```yaml
@@ -472,7 +455,6 @@ services:
volumes:
postgres_data:
```
#### MySQL/MariaDB 部署
```dockerfile
@@ -489,7 +471,6 @@ EXPOSE 3306
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD mariadb-admin ping -h localhost || exit 1
```
**自定义 my.cnf**
```ini
@@ -514,7 +495,6 @@ server_id = 1
log_bin = mysql-bin
binlog_format = ROW
```
#### Redis 缓存部署
```dockerfile
@@ -531,11 +511,9 @@ EXPOSE 6379
HEALTHCHECK --interval=5s --timeout=3s --retries=5 \
CMD redis-cli ping || exit 1
```
**redis.conf 配置**
```text
# 绑定地址
bind 0.0.0.0
@@ -567,7 +545,6 @@ 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 编排
**三层微服务架构示例**
@@ -704,7 +681,6 @@ networks:
backend-network:
driver: bridge
```
**nginx.conf 配置**
```nginx
@@ -760,7 +736,6 @@ server {
}
}
```
### 21.7.5 使用 VS Code Dev Containers
Dev Containers 让整个开发环境容器化提升团队一致性
@@ -823,7 +798,6 @@ Dev Containers 让整个开发环境容器化,提升团队一致性。
"remoteUser": "vscode"
}
```
**.devcontainer/Dockerfile**
```dockerfile
@@ -843,11 +817,9 @@ ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /workspace
```
**Docker Compose 用于 Dev Containers**
```yaml
# .devcontainer/docker-compose.yml
version: '3.9'