ly.system.api/Dockerfile
2025-01-08 15:09:25 +08:00

39 lines
1.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用官方的 Go 语言镜像作为基础镜像
# 这里使用 Go 1.23.0 版本的 Alpine Linux 镜像
FROM golang:1.23.2-alpine AS builder
# 设置工作目录为 /app
# 所有后续操作都会在这个目录下进行
WORKDIR /app
# 将配置文件添加到镜像
COPY config /app/config
# 将当前项目目录的所有文件拷贝到容器的 /app 目录中
COPY . .
# 设置 Go 模块代理为 https://goproxy.cn在中国加速模块下载并下载项目的依赖
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
# 编译 Go 项目,生成可执行文件 user-center
RUN go build -o user-center
# 使用一个更小的基础镜像Alpine来运行应用程序
# Alpine 是一个极简的 Linux 发行版,适合部署阶段
FROM alpine:latest
# 安装 tzdata 包,确保支持时区的配置
RUN apk add --no-cache tzdata
# 设置工作目录为 /app
WORKDIR /app
# 从编译阶段的镜像中拷贝编译后的二进制文件到运行镜像中
COPY --from=builder /app/user-center /app/user-center
# 暴露容器的 8999 端口,用于外部访问
EXPOSE 8999
# 设置容器启动时运行的命令
# 这里是运行编译好的可执行文件 demp-project
CMD ["/app/user-center"]