-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
# 阶段一:构建阶段 | ||
FROM golang:1.21 AS builder | ||
FROM golang:1.21.1-alpine3.18 AS builder | ||
|
||
# 设置工作目录为 /app | ||
WORKDIR /app | ||
# 安装 UPX 压缩工具 | ||
RUN apk --no-cache add curl xz && \ | ||
curl -L -o upx.tar.xz https://github.com/upx/upx/releases/latest/download/upx-4.1.0-amd64_linux.tar.xz && \ | ||
tar -xJf upx.tar.xz && \ | ||
mv upx-*-amd64_linux/upx /usr/local/bin/ && \ | ||
rm -rf upx.tar.xz upx-* | ||
|
||
# 设置工作目录 | ||
WORKDIR /build | ||
|
||
# 复制Go程序文件到容器中 | ||
COPY . . | ||
|
||
# 构建Go程序 | ||
RUN go build -o "connect_jxyy_network" | ||
RUN go build -o connect_jxyy_network | ||
|
||
# 压缩可执行文件 | ||
RUN upx -9 connect_jxyy_network | ||
|
||
# 阶段二:运行阶段 | ||
FROM alpine:latest | ||
|
||
# 设置工作目录为 /app | ||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 从第一阶段中复制生成的可执行文件到当前容器 | ||
COPY --from=builder "/app/connect_jxyy_network" "/app/connect_jxyy_network" | ||
|
||
# 暴露容器的端口号 | ||
EXPOSE 8080 | ||
COPY --from=builder /build/connect_jxyy_network /app/connect_jxyy_network | ||
|
||
# 定义启动容器时运行的命令 | ||
CMD ["/app/connect_jxyy_network"] |