完成所有部分的dockerfile编写
This commit is contained in:
19
management/Dockerfile
Normal file
19
management/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# 基础镜像:使用官方Nginx(Alpine版本,体积更小)
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# 维护者信息(可选)
|
||||||
|
LABEL maintainer="Mayiming"
|
||||||
|
|
||||||
|
# 将本地打包后的静态文件(dist目录)复制到Nginx的默认站点目录
|
||||||
|
# Nginx默认会从 /usr/share/nginx/html 目录加载静态文件
|
||||||
|
COPY dist/ /usr/share/nginx/html/
|
||||||
|
|
||||||
|
# (可选)如果需要自定义Nginx配置,复制本地的nginx.conf到容器的Nginx配置目录
|
||||||
|
# 覆盖默认的配置(解决SPA路由问题时需要)
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# 暴露容器的80端口(Nginx默认监听80端口)
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# 容器启动时自动启动Nginx(官方Nginx镜像已默认配置,可省略)
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
37
server/Dockerfile
Normal file
37
server/Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# 第一阶段:编译 Go 程序(使用 Go 1.24 官方镜像)
|
||||||
|
FROM golang:1.24-alpine AS builder
|
||||||
|
|
||||||
|
# 设置工作目录(容器内)
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制依赖文件,利用 Docker 缓存加速构建
|
||||||
|
COPY go.mod ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# 复制项目源码
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 编译程序:Go 1.24 支持更多优化,保持原命令即可(兼容旧版)
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o myproject main.go
|
||||||
|
|
||||||
|
# 第二阶段:构建轻量镜像
|
||||||
|
FROM alpine:3.20
|
||||||
|
|
||||||
|
# 安装必要依赖(Go 1.24 编译的程序可能依赖最新的 libc)
|
||||||
|
RUN apk --no-cache add ca-certificates tzdata
|
||||||
|
|
||||||
|
# 设置时区(可选)
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制编译产物和配置文件
|
||||||
|
COPY --from=builder /app/myproject ./
|
||||||
|
COPY --from=builder /app/config ./config/
|
||||||
|
COPY --from=builder /app/database ./database
|
||||||
|
|
||||||
|
# 暴露端口(根据你的 config 配置修改)
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# 启动命令
|
||||||
|
CMD ["./myproject"]
|
||||||
19
web/Dockerfile
Normal file
19
web/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# 基础镜像:使用官方Nginx(Alpine版本,体积更小)
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# 维护者信息(可选)
|
||||||
|
LABEL maintainer="Mayiming"
|
||||||
|
|
||||||
|
# 将本地打包后的静态文件(dist目录)复制到Nginx的默认站点目录
|
||||||
|
# Nginx默认会从 /usr/share/nginx/html 目录加载静态文件
|
||||||
|
COPY dist/ /usr/share/nginx/html/
|
||||||
|
|
||||||
|
# (可选)如果需要自定义Nginx配置,复制本地的nginx.conf到容器的Nginx配置目录
|
||||||
|
# 覆盖默认的配置(解决SPA路由问题时需要)
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# 暴露容器的80端口(Nginx默认监听80端口)
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# 容器启动时自动启动Nginx(官方Nginx镜像已默认配置,可省略)
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
Reference in New Issue
Block a user