更新 Dockerfile
This commit is contained in:
20
Dockerfile
20
Dockerfile
@@ -3,22 +3,29 @@ FROM golang:1.25-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 go.mod 和源代码
|
||||
COPY go.mod ./
|
||||
# 安装依赖
|
||||
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 siteproxy .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o siteproxy .
|
||||
|
||||
# 运行阶段
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
RUN apk --no-cache add ca-certificates tzdata
|
||||
|
||||
WORKDIR /root/
|
||||
WORKDIR /app
|
||||
|
||||
# 从构建阶段复制二进制文件
|
||||
# 从构建阶段复制二进制文件和模板
|
||||
COPY --from=builder /app/siteproxy .
|
||||
COPY --from=builder /app/templates ./templates
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8080
|
||||
@@ -29,3 +36,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
|
||||
# 运行
|
||||
CMD ["./siteproxy"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user