首页 > 解决方案 > 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 正常启动?

标签: reactjsdocker

解决方案


我想问题是stdin在你运行时关闭npm start

解决方案 1

添加stdin_open: truedocker-compose.yml

解决方案 2

将以下内容添加到您的Dockerfile

 ENV CI=true

推荐阅读