首页 > 解决方案 > 运行 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.htmlpublic.

有什么帮助吗?

标签: docker

解决方案


好像您没有复制 Dockerfile 中的代码,因为没有复制指令 execpt package.json?

在你的 Dockerfile 中添加这个

COPY . /frontend/

推荐阅读