【问题标题】:docker-compose command 'npm start' does not start react app automatically?docker-compose 命令“npm start”不会自动启动反应应用程序?
【发布时间】: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 正常启动?

【问题讨论】:

  • 你找到答案了吗?

标签: reactjs docker


【解决方案1】:

我想问题是当您运行 npm startstdin 会关闭。

解决方案 1

stdin_open: true 添加到docker-compose.yml

解决方案 2

将以下内容添加到您的Dockerfile

 ENV CI=true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2023-01-13
    • 2021-02-21
    • 2021-04-23
    • 2018-12-10
    • 2020-10-18
    • 1970-01-01
    • 2020-09-30
    相关资源
    最近更新 更多