【问题标题】:Docker container exited abruptly during react-scripts startDocker 容器在 react-scripts 启动期间突然退出
【发布时间】:2020-08-11 17:42:17
【问题描述】:

我想在 Docker 中运行一个简单的 React 应用程序。它在外面运行良好,但是当我尝试从 docker 运行它时,出现以下错误,目前我不知道。

custportal_1         | yarn run v1.15.2
custportal_1         | $ react-scripts start
custportal_1         | ℹ 「wds」: Project is running at http://172.24.0.12/
custportal_1         | ℹ 「wds」: webpack output is served from 
custportal_1         | ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
custportal_1         | ℹ 「wds」: 404s will fallback to /
custportal_1         | Starting the development server...
custportal_1         | 
custportal_1         | Done in 2.61s.
custportal_1 exited with code 0

应用程序由 create-react-app 命令创建。我的 Dockerfile 配置是

FROM node:11 as build-deps
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build

同样,应用程序在外部运行良好,但在 Docker 内部调用时中断。在 docker-compose 我用

调用容器
command: bash -c "export PORT=8081 && yarn start"

** 我在后台运行了 nginx 反向代理。

【问题讨论】:

标签: reactjs


【解决方案1】:

在 docker-compose 中添加stdin_open: true 可以解决问题。花了好几个小时才得到这个解决方案。参考github

我还注意到 react-script 在启动期间突然在 docker 内调用浏览器。在docker内部没有必要。添加像BROWSER=none 这样的环境变量可以省略这种行为。

编码愉快..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 2019-07-13
    • 2020-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    相关资源
    最近更新 更多