reactjs - docker-compose 命令'npm start'不会自动启动反应应用程序?
问题描述
我对反应应用程序相当陌生。
docker-compose 命令'npm start'不会自动启动反应应用程序?
包.json:
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
码头工人撰写:
.....:
command: bash -c "npm start && nginx -g 'daemon off;' "
日志输出:
portals_1 |
portals_1 | > myreact@0.1.0 start /~/~/myreact
portals_1 | > react-scripts start
portals_1 |
portals_1 | ℹ 「wds」: Project is running at http://172.18.0.9/
portals_1 | ℹ 「wds」: webpack output is served from
portals_1 | ℹ 「wds」: Content not from webpack is served from /~/~/myreact/public
portals_1 | ℹ 「wds」: 404s will fallback to /
portals_1 | Starting the development server...
portals_1 |
此时,docker 容器运行,但 react server 没有。但是,如果我 bash 进入 docker 容器
docker-compose exec portals bash
我检查端口 3000 是否仍然空闲。如果我进入目录并运行,npm start
则反应正常运行,一切都按预期进行。
日志输出: - 您现在可以在浏览器中查看 myreact。
Local: http://localhost:3000
On Your Network: http://172.18.0.9:3000
Note that the development build is not optimized.
To create a production build, use npm run build.......
为什么反应应用程序无法从 docker-compose 正常启动?
解决方案
我想问题是stdin
在你运行时关闭npm start
。
解决方案 1
添加stdin_open: true
到docker-compose.yml
解决方案 2
将以下内容添加到您的Dockerfile
ENV CI=true
推荐阅读
- angular - Jasmine/Karma - 第一个测试用例总是失败
- ios - 如何使用 FCM 为富文本通知创建有效负载
- angular - 如何对 *.spec.ts 文件使用不同的 tslint.json
- python - 在 Python 中导入证书透明度
- javascript - 如何将实时流 WAV 格式的音频数据馈送到 html5 音频标签
- gcloud - gcloud container create node pool with node taints command error
- reactjs - 使用装饰时 Object(...) 不是函数
- javascript - 复选框中的Vuejs单击事件?
- spring - Spring Webflow:跳过视图状态/转换自动选择
- grafana-api - 无法使用 HTTP API 创建 Grafana 用户