升级Dockerfile
This commit is contained in:
parent
d916949d3c
commit
e6453865c5
11
Dockerfile
11
Dockerfile
@ -4,29 +4,22 @@ FROM golang:1.23-alpine AS builder
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制go mod和sum文件
|
||||
COPY go.mod go.sum ./
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 下载依赖
|
||||
RUN go mod download
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建应用
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
||||
|
||||
# 使用轻量级的alpine作为运行环境
|
||||
FROM alpine:latest
|
||||
|
||||
# 安装必要的CA证书
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# 从builder阶段复制编译好的应用
|
||||
COPY --from=builder /app/main .
|
||||
COPY .env .
|
||||
|
||||
# 暴露应用端口(根据实际需要修改)
|
||||
EXPOSE 8080
|
||||
|
Loading…
x
Reference in New Issue
Block a user