阶段2(下):运维专题 Docker/Nginx/Linux/CI-CD/Git 的课程、企业场景、面试题和可运行示例

This commit is contained in:
Shikui Wang committed 2026-10-23 15:36:06 +08:00
1 parent 5eb67c5d08
commit b8010a74f3
42 files changed
+3533 -55

No files matched your search

@@ -0,0 +1,19 @@
# syntax=docker/dockerfile:1
# ---------- 构建阶段:带完整 Go 工具链 ----------
FROM golang:1.26-alpine AS build
WORKDIR /src
# 先只复制依赖描述文件,依赖不变时这一层可以复用缓存
COPY go.mod ./
RUN go mod download
COPY . .
# 静态编译,去掉调试信息减小体积
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/api .
# ---------- 运行阶段:只放二进制 ----------
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/api /api
ENV PORT=8080
EXPOSE 8080
USER nonroot:nonroot
# exec 形式,进程是 PID 1,能直接收到 SIGTERM
ENTRYPOINT ["/api"]