com.snow.auto_monitor/Dockerfile

43 lines
1.0 KiB
Docker
Raw Normal View History

2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 使用官方Go镜像作为构建环境
FROM golang:alpine AS builder
2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 设置工作目录
WORKDIR /app
2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 复制项目源码
COPY . .
2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 复制go模块依赖文件
COPY go.mod go.sum ./
2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 安装go模块依赖
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN go mod tidy
2024-07-15 16:44:58 +08:00
2024-09-29 12:04:36 +08:00
# 编译Go应用程序生成静态链接的二进制文件
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .
2024-07-15 16:44:58 +08:00
# 创建最终镜像用于运行编译后的Go程序
FROM alpine
ENV server = "admin"
# 设置工作目录
WORKDIR /app
# 将编译好的二进制文件从构建阶段复制到运行阶段
2024-09-29 12:04:36 +08:00
COPY --from=builder /app/server .
2024-07-15 16:44:58 +08:00
#COPY --from=builder /app/server .
COPY .env .
# 设置容器启动时运行的命令
2024-09-29 12:04:36 +08:00
ENTRYPOINT ["/app/server", "-a", "$server"]
# docker build . -t auto-monitor
# docker save -o auto-monitor.tar auto-monitor
# docker load -i auto-monitor.tar
#docker run -itd --name auto_monitor --network default_network -v /home/project/auto_monitor/logs:/app/logs -v /etc/localtime:/etc/localtime:ro -p 8999:8999 auto-monitor -a api