【发布时间】:2020-08-31 16:59:29
【问题描述】:
我对 React 应用程序相当陌生。
docker-compose 命令 'npm start' 不会自动启动 react app?
package.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,那么 react 会正常运行,一切都按预期进行。
日志输出:- 您现在可以在浏览器中查看 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.......
为什么 react 应用程序无法从 docker-compose 正常启动?
【问题讨论】:
-
你找到答案了吗?