alcex commited on
Commit
34cf54b
·
verified ·
1 Parent(s): f75adcf

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -0
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方的 Golang 镜像作为基础镜像
2
+ FROM golang:1.20-alpine AS builder
3
+
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # 将 Go 模块文件复制到工作目录
8
+ COPY go.mod go.sum ./
9
+
10
+ # 下载依赖
11
+ RUN go mod download
12
+
13
+ # 将项目源代码复制到工作目录
14
+ COPY . .
15
+
16
+ # 构建 Go 项目
17
+ RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .
18
+
19
+ # 使用轻量级的 Alpine 镜像作为运行环境
20
+ FROM alpine:latest
21
+
22
+ # 设置工作目录
23
+ WORKDIR /root/
24
+
25
+ # 从 builder 阶段复制构建好的可执行文件
26
+ COPY --from=builder /app/myapp .
27
+
28
+ # 暴露应用程序运行的端口(根据实际情况修改)
29
+ EXPOSE 8080
30
+
31
+ # 运行应用程序
32
+ CMD ["./myapp"]