update docker build

main
dugulingping 2024-01-21 22:49:55 +08:00
parent 2fe4b0193e
commit ccade90df4
2 changed files with 38 additions and 0 deletions

29
Dockerfile Normal file
View File

@ -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"]

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
version: '3'
services:
lucky-tools:
image: .
ports:
- "8080:8080"
volumes:
- ./mappings.db:/app/mappings.db