-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.alpine
More file actions
53 lines (37 loc) · 1.12 KB
/
Dockerfile.alpine
File metadata and controls
53 lines (37 loc) · 1.12 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
# 使用官方 Rust 镜像作为构建环境
FROM rust:1.75-alpine as builder
# 安装构建依赖
RUN apk add --no-cache musl-dev
# 设置工作目录
WORKDIR /usr/src/app
# 复制 Cargo.toml 和 Cargo.lock(如果存在)
COPY Cargo.toml Cargo.lock ./
# 复制源代码
COPY src ./src
COPY benches ./benches
COPY config ./config
# 构建应用程序
RUN cargo build --release --bin snowflake_server
# 使用 Alpine Linux 作为运行时镜像
FROM alpine:latest
# 安装运行时依赖
RUN apk add --no-cache ca-certificates curl
# 创建非 root 用户
RUN adduser -D -s /bin/sh snowflake
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /usr/src/app/target/release/snowflake_server ./snowflake_server
# 复制配置文件
COPY --from=builder /usr/src/app/config ./config
# 设置权限
RUN chown -R snowflake:snowflake /app
# 切换到非 root 用户
USER snowflake
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# 运行应用程序
CMD ["./snowflake_server"]