运行React Dockerfile给我一个错误

时间:2019-10-02 02:21:50

标签: docker

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开始/ frontend   反应脚本开始

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

有帮助吗?

1 个答案:

答案 0 :(得分:1)

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

将此添加到您的Dockerfile

COPY . /frontend/