- Removed the build stage from the Dockerfile, simplifying the image creation process. - Updated the Dockerfile to directly copy the pre-built binary instead of using a multi-stage build. - Modified the build workflow to eliminate unnecessary build arguments, streamlining the configuration.
36 lines
767 B
Docker
36 lines
767 B
Docker
# 运行阶段
|
|
FROM alpine:latest
|
|
|
|
# 安装必要的运行时依赖
|
|
RUN apk add --no-cache ca-certificates tzdata wget
|
|
|
|
# 创建非 root 用户
|
|
RUN addgroup -g 1000 appuser && \
|
|
adduser -D -u 1000 -G appuser appuser
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 复制已经编译好的二进制文件
|
|
ARG BINARY_NAME=mcauth-linux-amd64
|
|
COPY ${BINARY_NAME} /app/server
|
|
|
|
# 复制配置文件(如果需要)
|
|
COPY configs/ /app/configs/
|
|
|
|
# 设置权限
|
|
RUN chown -R appuser:appuser /app
|
|
|
|
# 切换到非 root 用户
|
|
USER appuser
|
|
|
|
# 暴露端口
|
|
EXPOSE 8080
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
|
|
|
# 启动应用
|
|
ENTRYPOINT ["/app/server"]
|