docker - 运行 React Dockerfile 给我一个错误
问题描述
FROM node:latest
WORKDIR /frontend/
ENV PATH /frontend/node_modules/.bin:$PATH
COPY package.json /frontend/package.json
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
CMD ["npm", "run", "start"]
这就是我通过 Dockerfile 为我的 React 前端构建的方式。我曾经docker build -t frontend:dev .
构建它并docker run -p 3001:3000 --rm frontend:dev
运行它。
然而,这给了我,
frontend@0.1.0 start /frontend react-scripts start
Could not find a required file.
Name: index.html
Searched in: /frontend/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.1.0 start: `react-scripts start`ts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
虽然我可以index.html
在public
.
有什么帮助吗?
解决方案
好像您没有复制 Dockerfile 中的代码,因为没有复制指令 execpt package.json?
在你的 Dockerfile 中添加这个
COPY . /frontend/
推荐阅读
- regex - 正则表达式匹配无限的一个字符,但只有两个另一个
- python - Keras LSTM:ValueError:检查目标时出错:预期dense_1具有2维,但得到的数组具有形状(1440、60、1)
- python - 如何更改输入或 tkinter 输入框的列顺序?
- excel - .htmlbody 中的选择不会接受多个单元格进行复制
- tensorflow - 尝试训练模型时出现 OOM 错误
- macos - Mac 上的 Flutter SDK 路径
- google-apps-script - 如何以编程方式*删除* Apps 脚本中的 Google 表格菜单项
- scala - 如何列出 Scala 对象中的所有对象?
- excel - 从字典 VBA 中提取存储的数据
- javascript - 如何查询和更新mongodb子文档