From 302740186c44bada927054295cab1177ae442b68 Mon Sep 17 00:00:00 2001 From: wuchao <1272174216@qq.com> Date: Thu, 28 Nov 2024 09:17:35 +0800 Subject: [PATCH] =?UTF-8?q?Dockerfile=20=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Dockerfile diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..a5ff17d --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,44 @@ + +## 使用官方Go镜像作为构建环境 +#FROM golang:1.21.0 AS builder +# +## 设置工作目录 +#WORKDIR /app +# +## 复制项目源码 +#COPY . . +# +## 复制go模块依赖文件 +#COPY go.mod go.sum ./ +# +## 安装go模块依赖 +#RUN go env -w GOPROXY=https://goproxy.cn,direct +#RUN go mod tidy +# +## 编译Go应用程序,生成静态链接的二进制文件 +#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server . + +# 创建最终镜像,用于运行编译后的Go程序 +FROM alpine + +RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \ +&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \ +&& apk update && apk add tzdata \ +&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ +&& echo "Asia/Shanghai" > /etc/timezone \ + +ENV server = "admin" + +# 设置工作目录 +WORKDIR /app + +# 将编译好的二进制文件从构建阶段复制到运行阶段 +COPY /server . +#COPY --from=builder /app/server . +COPY .env . +COPY ./front ./front + + +ENV TZ=Asia/Shanghai +# 设置容器启动时运行的命令 +ENTRYPOINT ["/app/server", "-a", "$server"] \ No newline at end of file