-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (32 loc) · 861 Bytes
/
Dockerfile
File metadata and controls
47 lines (32 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 构建阶段
FROM golang:1.21-alpine AS builder
WORKDIR /build
# 安装 build dependencies
RUN apk add --no-cache git
# 复制 go.mod 和 go.sum
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码
COPY . .
# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o nginxgo ./cmd/nginxgo
# 运行阶段
FROM alpine:latest
# 安装 ca-certificates 用于 HTTPS
RUN apk --no-cache add ca-certificates
# 创建非 root 用户
RUN adduser -D -u 1000 nginxgo
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /build/nginxgo .
# 复制配置文件和静态文件
COPY conf/nginx.conf ./conf/
COPY html ./html/
# 创建日志目录
RUN mkdir -p logs && chown -R nginxgo:nginxgo .
# 切换到非 root 用户
USER nginxgo
# 暴露端口
EXPOSE 80
# 启动命令
CMD ["./nginxgo", "-c", "conf/nginx.conf"]