reactjs - react-scripts 开始在 docker 前台 cmd 中退出

如何调试 react-scripts 启动?

这工作正常,我不知道发生了什么变化(我没有改变任何东西)

看来 react-scripts start 无法作为前台进程继续运行。

我的 Dockerfile:

FROM centos:7

EXPOSE 3000/tcp

RUN yum update -y && yum install -y unzip wget nano epel-release yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm wget nano yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm

RUN curl -sL https://rpm.nodesource.com/setup_13.x | bash -
RUN yum install -y nodejs

RUN mkdir /data
COPY ./src /data

COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]

CMD ["npm", "run", "start"]

docker-entrypoint.sh:
#!/bin/bash
set -e
#rm -f /usr/sbin/suexec
cd /data;npm install

exec "$@"

包.json
    {
  "name": "my-gui",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.7",
    "@material-ui/icons": "^4.9.1",
    "@types/lodash": "^4.14.149",
    "@types/react": "^16.9.25",
    "@types/react-dom": "^16.9.5",
    "@types/validator": "^12.0.1",
    "axios": "^0.19.2",
    "date-fns": "^2.11.0",
    "lodash": "^4.17.15",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "^3.4.1",
    "typescript": "^3.8.3",
    "validator": "^12.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

docker-compose.yml
version: '3'
services:

  gui:
    build: ./gui/
    ports:
      - "3000:3000"
    volumes:
      - ./gui/src:/data
      - node_modules:/data/node_modules
volumes:  
  node_modules: {}

当我尝试启动 docker-compose 时,我得到以下输出:
Recreating myapp_gui_1 ... 
Recreating myapp_gui_1 ... done
Attaching to myapp_gui_1
gui_1  | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
gui_1  | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
gui_1  | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules/webpack-dev-server/node_modules/fsevents):
gui_1  | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
gui_1  | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules/watchpack/node_modules/fsevents):
gui_1  | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
gui_1  | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules/jest-haste-map/node_modules/fsevents):
gui_1  | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
gui_1  | 
gui_1  | audited 930195 packages in 7.762s
gui_1  | 
gui_1  | 59 packages are looking for funding
gui_1  |   run `npm fund` for details
gui_1  | 
gui_1  | found 2 low severity vulnerabilities
gui_1  |   run `npm audit fix` to fix them, or `npm audit` for details
gui_1  | 
gui_1  | > iso-form-gui@0.0.0 start /data
gui_1  | > react-scripts start
gui_1  | 
gui_1  | ℹ 「wds」: Project is running at http://172.20.0.2/
gui_1  | ℹ 「wds」: webpack output is served from 
gui_1  | ℹ 「wds」: Content not from webpack is served from /data/public
gui_1  | ℹ 「wds」: 404s will fallback to /
gui_1  | Starting the development server...
gui_1  | 
myapp_gui_1 exited with code 0

如果我在 docker 之外运行 react-scripts start (npm start),它工作正常。

最佳答案

我遇到了同样的问题。
我的解决方法是将 stdin_open: true 添加到我的 docker-compose.yml

version: "3"
services:
  web:
    build: 
        context: .
        dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - /app/node_modules
      - .:/app
    stdin_open: true

https://stackoverflow.com/questions/60790696/

相关文章:

c# - Emgu.CV在Windows 7 x64上不起作用

android - 我可以使用openCV4Android处理Android相机录制的视频吗?

docker - 无法安装 Docker - 哈希和不匹配(Ubuntu 18.04、Vagrant

python - 质心计算程序中的时间滞后

opencv - 更改图像opencv的宽度步长

python - GUI 卡住了其余的 python 代码

android - 在 JNI/Android 中初始化 C++ 对象一次

opencv - OpenCV旋转的图像显示时形状不正确

performance - 我应该在 HBase 中使用 prefixfilter 还是 rowke

docker - Docker端口映射在Windows 10上不起作用