chore: update content and add generated PDF

This commit is contained in:
Baohua Yang
2026-03-27 08:43:47 -07:00
parent 046d241ee5
commit b67d5367dc
10 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ jwilder/nginx-proxy:latest
## 其他 Registry ## 其他 Registry
ghcr.io/username/myapp:v1.0 ghcr.io/username/myapp:v1.0
gcr.io/google-containers/pause:3.6 gcr.io/google-containers/pause:3.10
``` ```
> 💡 **笔者提示**如果不指定 Registry 地址默认使用 Docker Hub如果不指定标签默认使用 `latest` > 💡 **笔者提示**如果不指定 Registry 地址默认使用 Docker Hub如果不指定标签默认使用 `latest`
+1 -1
View File
@@ -227,7 +227,7 @@ FROM ${BASE_IMAGE}
## 可以构建不同基础镜像的版本 ## 可以构建不同基础镜像的版本
## docker build --build-arg BASE_IMAGE=python:3.11-alpine . ## docker build --build-arg BASE_IMAGE=python:3.14-alpine .
... ...
``` ```
+2 -2
View File
@@ -64,12 +64,12 @@ $ docker run --rm -it \
```bash ```bash
## 如果使用本地命令行扫描容器镜像 ## 如果使用本地命令行扫描容器镜像
$ trivy image alpine:3.10 $ trivy image alpine:3.20
2024-03-01T10:05:07.124Z INFO Number of language-specific files: 1 2024-03-01T10:05:07.124Z INFO Number of language-specific files: 1
2024-03-01T10:05:07.124Z INFO Detecting vulnerabilities... 2024-03-01T10:05:07.124Z INFO Detecting vulnerabilities...
alpine:3.10 (alpine 3.10.3) alpine:3.20 (alpine 3.10.3)
=========================== ===========================
Total: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 1, CRITICAL: 0) Total: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 1, CRITICAL: 0)
+1 -1
View File
@@ -301,7 +301,7 @@ RUN apt-get update && apt-get install -y curl=7.68.0-1ubuntu1
Dockerfile 中集成安全扫描 Dockerfile 中集成安全扫描
```dockerfile ```dockerfile
FROM golang:1.20-alpine AS builder FROM golang:1.26-alpine AS builder
WORKDIR /app WORKDIR /app
COPY . . COPY . .
@@ -305,7 +305,7 @@ journalctl -u docker -n 100 | grep -i "oom"
```python ```python
# Dockerfile # Dockerfile
FROM python:3.11-slim FROM python:3.14-slim
WORKDIR /app WORKDIR /app
COPY requirements.txt . COPY requirements.txt .
RUN pip install -r requirements.txt memory_profiler tracemalloc RUN pip install -r requirements.txt memory_profiler tracemalloc
@@ -424,7 +424,7 @@ chmod +x hadolint
```dockerfile ```dockerfile
# Stage 1: 构建阶段 # Stage 1: 构建阶段
FROM golang:1.20-alpine AS builder FROM golang:1.26-alpine AS builder
WORKDIR /build WORKDIR /build
@@ -453,13 +453,13 @@ COPY --from=builder /build/app /app
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/app"] ENTRYPOINT ["/app"]
# 最终镜像大小通常 < 15MB(相比 golang:1.20-alpine 的 ~1GB # 最终镜像大小通常 < 15MB(相比 golang:1.26-alpine 的 ~1GB
``` ```
**Node.js 应用的多阶段构建** **Node.js 应用的多阶段构建**
```dockerfile ```dockerfile
# Stage 1: 依赖安装 # Stage 1: 依赖安装
FROM node:18-alpine AS dependencies FROM node:24-alpine AS dependencies
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
@@ -467,7 +467,7 @@ RUN npm ci --only=production && \
npm cache clean --force npm cache clean --force
# Stage 2: 构建阶段 # Stage 2: 构建阶段
FROM node:18-alpine AS builder FROM node:24-alpine AS builder
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
@@ -477,7 +477,7 @@ COPY . .
RUN npm run build RUN npm run build
# Stage 3: 运行阶段 # Stage 3: 运行阶段
FROM node:18-alpine FROM node:24-alpine
WORKDIR /app WORKDIR /app
@@ -504,7 +504,7 @@ CMD ["node", "dist/index.js"]
```dockerfile ```dockerfile
# Stage 1: 构建阶段 # Stage 1: 构建阶段
FROM python:3.11-slim AS builder FROM python:3.14-slim AS builder
WORKDIR /build WORKDIR /build
@@ -516,7 +516,7 @@ COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt RUN pip install --user --no-cache-dir -r requirements.txt
# Stage 2: 运行阶段 # Stage 2: 运行阶段
FROM python:3.11-slim FROM python:3.14-slim
WORKDIR /app WORKDIR /app
@@ -550,7 +550,7 @@ CMD ["python", "app.py"]
□ 使用 BuildKit 缓存优化加速构建 □ 使用 BuildKit 缓存优化加速构建
# 优化示例: # 优化示例:
FROM ubuntu:22.04 FROM ubuntu:24.04
# ❌ 不推荐 # ❌ 不推荐
RUN apt-get update RUN apt-get update
+2 -2
View File
@@ -23,7 +23,7 @@
```dockerfile ```dockerfile
## Build stage ## Build stage
FROM golang:1.23 AS builder FROM golang:1.26 AS builder
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN go build -o main . RUN go build -o main .
@@ -48,7 +48,7 @@ stages:
unit_test: unit_test:
stage: test stage: test
image: golang:1.23 image: golang:1.26
script: script:
- go test ./... - go test ./...
+1 -1
View File
@@ -17,7 +17,7 @@ VS Code 的 [Dev Containers](https://code.visualstudio.com/docs/devcontainers/co
```json ```json
{ {
"name": "docker-practice-dev", "name": "docker-practice-dev",
"image": "golang:1.22", "image": "golang:1.26",
"workspaceFolder": "/work", "workspaceFolder": "/work",
"workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind", "workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind",
"customizations": { "customizations": {
+6 -6
View File
@@ -48,7 +48,7 @@ func main() {
```dockerfile ```dockerfile
# Stage 1: 构建阶段 # Stage 1: 构建阶段
FROM golang:1.20-alpine AS builder FROM golang:1.26-alpine AS builder
WORKDIR /build WORKDIR /build
@@ -106,7 +106,7 @@ docker exec go-demo ls -la /
# 只包含 /app 和系统必要文件 # 只包含 /app 和系统必要文件
# 镜像大小通常 < 10MB相比 golang:1.20-alpine ~1GB # 镜像大小通常 < 10MB相比 golang:1.26-alpine ~1GB
docker history go-app:latest docker history go-app:latest
``` ```
**go.mod go.sum 示例** **go.mod go.sum 示例**
@@ -114,7 +114,7 @@ docker history go-app:latest
```text ```text
module github.com/example/go-app module github.com/example/go-app
go 1.20 go 1.26
require ( require (
// 如果需要依赖 // 如果需要依赖
@@ -154,7 +154,7 @@ func main() {
**优化的 Dockerfile** **优化的 Dockerfile**
```dockerfile ```dockerfile
FROM golang:1.20-alpine AS builder FROM golang:1.26-alpine AS builder
WORKDIR /src WORKDIR /src
@@ -746,7 +746,7 @@ Dev Containers 让整个开发环境容器化,提升团队一致性。
```json ```json
{ {
"name": "Python Dev Environment", "name": "Python Dev Environment",
"image": "mcr.microsoft.com/devcontainers/python:3.11", "image": "mcr.microsoft.com/devcontainers/python:3.14",
"features": { "features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/devcontainers/features/docker-in-docker:2": {},
@@ -802,7 +802,7 @@ Dev Containers 让整个开发环境容器化,提升团队一致性。
**.devcontainer/Dockerfile** **.devcontainer/Dockerfile**
```dockerfile ```dockerfile
FROM mcr.microsoft.com/devcontainers/python:3.11 FROM mcr.microsoft.com/devcontainers/python:3.14
# 安装额外工具 # 安装额外工具
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
+1 -1
View File
@@ -574,7 +574,7 @@ A(要点):
A要点 A要点
```text ```text
1. 选择合适的基础镜像 1. 选择合适的基础镜像
scratch < alpine:3.17 < python:3.11-slim < python:3.11 scratch < alpine:3.17 < python:3.14-slim < python:3.14
2. 多阶段构建 2. 多阶段构建
- 构建阶段只保留编译工具 - 构建阶段只保留编译工具
Binary file not shown.