sanbo110 commited on
Commit
d78fa81
·
verified ·
1 Parent(s): f9f4ba1

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +0 -19
Dockerfile CHANGED
@@ -1,43 +1,24 @@
1
- # 构建阶段
2
- FROM golang:1.22-alpine AS builder
3
-
4
- # 设置工作目录
5
  WORKDIR /app
6
 
7
- # 为了减少Docker层数,先复制 go.mod 和 go.sum 并下载依赖
8
  RUN go mod tidy
9
  COPY go.mod go.sum ./
10
  RUN go mod download
11
 
12
- # 复制源代码
13
  COPY . .
14
 
15
- # 编译Go应用,启用优化参数
16
  RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o test .
17
 
18
- # 运行阶段
19
  FROM alpine:3.18
20
-
21
- # 设置工作目录
22
  WORKDIR /app
23
 
24
- # 将编译好的二进制文件从构建阶段复制过来
25
  COPY --from=builder /app/test .
26
 
27
- # 设置环境变量
28
  ENV MAX_RETRY_COUNT=3
29
- ENV RETRY_DELAY=5000
30
- ENV PORT=7860
31
-
32
- # 公开端口
33
  EXPOSE 7860
34
 
35
- # 确保二进制文件具有可执行权限
36
  RUN chmod +x test
37
 
38
- # 使用非 root 用户运行应用(增强安全性)
39
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
40
  USER appuser
41
 
42
- # 启动应用
43
  ENTRYPOINT ["./test"]
 
 
 
 
 
1
  WORKDIR /app
2
 
 
3
  RUN go mod tidy
4
  COPY go.mod go.sum ./
5
  RUN go mod download
6
 
 
7
  COPY . .
8
 
 
9
  RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o test .
10
 
 
11
  FROM alpine:3.18
 
 
12
  WORKDIR /app
13
 
 
14
  COPY --from=builder /app/test .
15
 
 
16
  ENV MAX_RETRY_COUNT=3
 
 
 
 
17
  EXPOSE 7860
18
 
 
19
  RUN chmod +x test
20
 
 
21
  RUN addgroup -S appgroup && adduser -S appuser -G appgroup
22
  USER appuser
23
 
 
24
  ENTRYPOINT ["./test"]