diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6eb0ff6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# 使用官方Go镜像作为构建环境 +FROM golang:1.21.6 as builder + +# 设置工作目录 +WORKDIR /app + +# 复制go.mod和go.sum文件 +COPY go.mod go.sum ./ + +# 下载依赖项 +RUN go mod tidy + +# 复制源代码 +COPY . . + +# 构建应用程序 +RUN CGO_ENABLED=0 GOOS=linux go build -v -o server + +# 使用scratch作为基础镜像 +FROM scratch + +# 从builder镜像中复制编译好的应用程序 +COPY --from=builder /app/server /server + +# 暴露端口 +EXPOSE 8080 + +# 运行应用程序 +ENTRYPOINT ["/server"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c41fe90 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + lucky-tools: + image: . + ports: + - "8080:8080" + volumes: + - ./mappings.db:/app/mappings.db