# Dockerfile for a React app build and run FROM node:18.19.1-alpine AS builder MAINTAINER yaclty2@gmail.com WORKDIR /app # envs 配置 # 应用部署后的URL ENV APP_SITE_URL "" # 应用接口前缀 ENV APP_API_URL "" # Copy source code to the builder COPY package.json yarn.lock* ./ COPY public ./public COPY src ./src COPY index.html ./ COPY *.ts . COPY *.json . # Install dependencies and build the app RUN yarn install RUN yarn build-prod # Step 2. Production image, copy all the files and run nginx FROM nginx:1.26-alpine3.19 AS runner WORKDIR /app # envs 配置 ENV APP_API_URL localhost:50000 # nginx配置文件 #COPY nginx.conf /etc/nginx/conf.d/default.conf.template # 编译文件 COPY --from=builder /app/dist ./ # RUN /bin/sh envsubst /etc/nginx/templates/*.template /etc/nginx/conf.d #WORKDIR /etc/nginx/conf.d/ #ENTRYPOINT sed -i "s~~~" /app/index.html && envsubst '$APP_API_URL' < default.conf.template > default.conf && cat default.conf && nginx -g 'daemon off;' # 暴露80端口 EXPOSE 80 # 启动Nginx服务 CMD ["nginx", "-g", "daemon off;"]