# ============================================ # 前端镜像 — 宿主机构建 dist,Docker 打包 Nginx # 启动时通过 BACKEND_PROXY 环境变量指定后端地址 # ============================================ FROM nginx:alpine LABEL maintainer="ghb-base deploy" # 安装 envsubst(gettext 包提供) RUN apk add --no-cache gettext COPY deploy/nginx/default.conf /etc/nginx/templates/default.conf.template COPY dist /usr/share/nginx/html EXPOSE 80 # envsubst 会将模板中 ${BACKEND_PROXY} 替换为实际值 # 单体模式: http://ghb-backend:8081/ghb # Cloud 模式: http://ghb-gateway:9999/ghb ENV BACKEND_PROXY=http://ghb-backend:8081/ghb CMD ["/bin/sh", "-c", "envsubst '${BACKEND_PROXY}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]