dockerfile add

This commit is contained in:
2024-10-31 23:17:41 +08:00
parent 0aa07af0d4
commit ea8aea4ce2

26
Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
# 使用官方的 Go 运行时作为基础镜像
FROM golang:latest AS builder
# 设置工作目录
WORKDIR /app
# 将当前目录下的所有文件复制到工作目录中
COPY . .
# 构建可执行文件
RUN CGO_ENABLED=0 GOOS=linux go build -v -o app .
# 使用一个更小的基础镜像来减小最终镜像的大小
FROM alpine:latest
# 设置工作目录
WORKDIR /root/
# 从构建阶段复制可执行文件
COPY --from=builder /app/app .
# 暴露端口
EXPOSE 8080
# 运行可执行文件
CMD ["./app"]