add dockerfile

This commit is contained in:
zhangchao
2024-10-31 19:10:55 +08:00
parent c096a94351
commit 4b7192cb59
2 changed files with 58 additions and 13 deletions

26
Dokerfile.yaml Normal file
View File

@@ -0,0 +1,26 @@
# 使用官方的 Go 运行时作为基础镜像
FROM golang:1.18-alpine 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"]