reactjs - 如何使用服务器端渲染为 ReactJS 应用程序设置多阶段构建
问题描述
如何将其配置为多阶段构建
纱线开始映射到
"start": "nodemon ./server-build/index.js",
Dockerfile
FROM node:14.17.3-alpine AS build
RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm
RUN npm i nodemon -g
WORKDIR /app/web-web
ENV PATH /app/web-web/node_modules/.bin:$PATH
COPY package.json /app/web-web/package.json
RUN yarn install --network-timeout 1000000000
COPY . /app/web-web
RUN yarn run build:staging
COPY . /app/web-web
EXPOSE 3006
CMD ["yarn", "start"]
解决方案
警告未测试代码。
下面的 Dockerfile 未经测试,您必须将其视为起点。
缺少一些信息,这些apk
包仅用于构建或运行?
我建议您阅读有关多阶段构建的信息
###############################################################
# This stage do:
# 1. Install required software
# 2. Copy package.json and install deps
###############################################################
FROM node:14.17.3-alpine AS build
# This packet are required ONLY for build ??? Otherwise add on final stage
RUN apk add --no-cache build-base gcc autoconf automake libtool zlib-dev libpng-dev nasm
WORKDIR /app/web-web
ENV PATH /app/web-web/node_modules/.bin:$PATH
COPY package.json /app/web-web/package.json
RUN yarn install --network-timeout 1000000000
###############################################################
# This stage do:
# 1. copy node_modules from build stage to this image
# 2. build app and run
###############################################################
FROM node:14.17.3-alpine AS final
WORKDIR /app/web-web
# Magic append here: I copy from prev stage (build) to this one
COPY --from=build /app/web-web .
COPY . /app/web-web
RUN npm i nodemon -g
RUN yarn run build:staging
EXPOSE 3006
CMD ["yarn", "start"]
推荐阅读
- javascript - 循环时从对象中获取键值
- android - 如何通过 Ionic 中的 Cordova File 插件访问外部 USB 存储设备?
- r - R中的分组/计数/匹配数据
- csv - 在 Here Maps 中使用 csv 和 svg 创建基于位置的标记
- php - PHP 对象数组不包含正确的值
- python - 使用 python 发送邮件出错
- javascript - 盖茨比第二版布局模板
- javascript - 在 React 中深度克隆递归对象的正确方法(规范化状态)
- ios - 网页加载后活动指示器不隐藏
- javascript - 如果其他代码,我如何停止在此 JavaScript 中执行循环?