31 lines
651 B
Docker
31 lines
651 B
Docker
|
|
# 第一阶段:使用最新Go版本构建
|
|||
|
|
FROM golang:1.24 AS builder
|
|||
|
|
|
|||
|
|
WORKDIR /app
|
|||
|
|
|
|||
|
|
# 复制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 -ldflags="-s -w" -o videoplayer .
|
|||
|
|
|
|||
|
|
# 第二阶段:生产环境(最小化镜像)
|
|||
|
|
FROM scratch
|
|||
|
|
|
|||
|
|
# 复制配置文件
|
|||
|
|
COPY --from=builder /app/vp.conf /home/videoplayer/vp.conf
|
|||
|
|
|
|||
|
|
# 复制二进制文件
|
|||
|
|
COPY --from=builder /app/videoplayer /home/videoplayer/videoplayer
|
|||
|
|
|
|||
|
|
# 设置工作目录
|
|||
|
|
WORKDIR /home/videoplayer
|
|||
|
|
|
|||
|
|
# 暴露端口
|
|||
|
|
EXPOSE 8083
|
|||
|
|
|
|||
|
|
# 运行应用
|
|||
|
|
CMD ["./videoplayer"]
|