Create Dockerfile
Browse files- Dockerfile +35 -0
Dockerfile
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Build Stage
|
2 |
+
# 使用 golang:alpine 作为构建阶段的基础镜像
|
3 |
+
FROM golang:alpine AS builder
|
4 |
+
|
5 |
+
# 添加 git,以便之后能从GitHub克隆项目
|
6 |
+
RUN apk --no-cache add git
|
7 |
+
|
8 |
+
# 从 GitHub 克隆 go-proxy-bingai 项目到 /workspace/app 目录下
|
9 |
+
RUN git clone https://github.com/Harry-zklcdc/go-proxy-bingai.git /workspace/app
|
10 |
+
|
11 |
+
#设置工作目录为之前克隆的项目目录
|
12 |
+
WORKDIR /workspace/appe
|
13 |
+
|
14 |
+
#编译 go 项目。-ldflags="-s -w”是为了减少编译后的二进制大小
|
15 |
+
RUN go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go
|
16 |
+
|
17 |
+
# Runtime Stage
|
18 |
+
# 使用轻量级的 alpine 镜像作为运行时的基础镜像
|
19 |
+
FROM alpine
|
20 |
+
|
21 |
+
# 设置工作目录
|
22 |
+
WORKDIR /workspace/app
|
23 |
+
|
24 |
+
# 从构建阶段复制编译后的二进制文件到运行时镜像中
|
25 |
+
COPY --from=builder /workspace/app/goproxy-bingai .
|
26 |
+
|
27 |
+
# 设置环境变量,此处为随机字符
|
28 |
+
ENV
|
29 |
+
Go_Proxy_BingALUSER_TOKENI="kJs8hD92ncMzLaoQWYtX5rG6bE3fZ4iO"
|
30 |
+
|
31 |
+
# 暴露8080端口
|
32 |
+
EXPOSE 8080
|
33 |
+
|
34 |
+
# 容器启动时运行的命令
|
35 |
+
CMD["/workspace/app/go-proxy-bingai"]
|