-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (47 loc) · 1.32 KB
/
Dockerfile
File metadata and controls
66 lines (47 loc) · 1.32 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# MediaProxy Dockerfile
# 多阶段构建,优化镜像大小
# 构建阶段
FROM golang:1.21-alpine AS builder
# 设置工作目录
WORKDIR /app
# 安装构建依赖
RUN apk add --no-cache git ca-certificates tzdata
# 复制go mod文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY . .
# 构建应用
ARG VERSION=dev
ARG BUILD_TIME
ARG GIT_COMMIT
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.GitCommit=${GIT_COMMIT}" \
-trimpath \
-o mediaProxy .
# 运行阶段
FROM alpine:latest
# 安装运行时依赖
RUN apk --no-cache add ca-certificates tzdata
# 创建非root用户
RUN addgroup -g 1001 -S mediaproxy && \
adduser -u 1001 -S mediaproxy -G mediaproxy
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /app/mediaProxy .
# 复制静态文件
COPY --from=builder /app/static ./static
# 设置文件权限
RUN chown -R mediaproxy:mediaproxy /app
# 切换到非root用户
USER mediaproxy
# 暴露端口
EXPOSE 57574
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:57574/ || exit 1
# 启动命令
ENTRYPOINT ["./mediaProxy"]
CMD ["-port", "57574"]