reactjs - React app exiting in docker container with exit code 0
问题描述
I am trying to create a docker-compose setup with nginzx, flask, and react. I started my react app with react-create-app (https://github.com/facebook/create-react-app) and haven't changed anything from it yet.
My Dockerfile for the react app is:
FROM node:10
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install --verbose
# Bundle app source
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
The compose script is:
version: '3.1'
services:
nginx:
image: nginx:1.15
container_name: nginx
volumes:
- ../:/var/www
- ./nginx-dev.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
networks:
- my-network
depends_on:
- flask
- react
react:
build:
context: ../react-app/
dockerfile: ./Dockerfile
container_name: react
volumes:
- ../react-app:/usr/src/app
networks:
my-network:
aliases:
- react-app
expose:
- 3000
ports:
- "3000:3000"
flask:
...
networks:
my-network:
The flask and nginx containers start fine, the output for react is:
react |
react | > react-app@0.1.0 start /usr/src/app
react | > react-scripts start
react |
react | ℹ 「wds」: Project is running at http://my-ip-address/
react | ℹ 「wds」: webpack output is served from
react | ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
react | ℹ 「wds」: 404s will fallback to /
react | Starting the development server...
react |
react |
react | npm verb lifecycle react-app@0.1.0~start: unsafe-perm in lifecycle true
react | npm verb lifecycle react-app@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/usr/src/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
react | npm verb lifecycle react-app@0.1.0~start: CWD: /usr/src/app
react | npm info lifecycle react-app@0.1.0~poststart: react-app@0.1.0
react | npm verb exit [ 0, true ]
react | npm timing npm Completed in 1727ms
react | npm info ok
react exited with code 0
解决方案
添加:stdin_open: true
到我的 docker-compose 文件的 React 组件修复了我的问题。
例子:
version: '3.1'
services:
react:
build:
context: ../react-app/
dockerfile: ./Dockerfile
container_name: react
volumes:
- ../react-app:/usr/src/app
networks:
my-network:
aliases:
- react-app
expose:
- 3000
ports:
- "3000:3000"
stdin_open: true
推荐阅读
- spring - 春季批处理 - 作业在 STARDED 状态下仍然被阻止
- reactjs - react-helmet-async 包的 npm 对等依赖项使用 React 17 时出错
- r-markdown - Rmarkdown 绘图和图像并排
- pdf - 有没有办法以编程方式识别/检测 PDF 或 Illustrator 文件中的形状?
- r-markdown - 在 Rstudio 中打开几天后的 R 笔记本松散图像
- linux - 查找当前目录的直接下一个目录列表以到达目标文件?
- java - 如何在 Apache PDFBox 中呈现彩色文本
- powershell - (Get-WmiObject) 如何更改“锁定”属性?
- sorting - 插入排序 - TStringList Delphi
- html - 最大宽度属性在 Outlook 桌面应用程序版本上不起作用,而在 Web 版本上做得很好?