Docker-Compose在启动使用CREATE-REACT-APP创建的Reaction应用程序后立即停止 [英] docker-compose stops immediately after starting react app created using create-react-app

查看:4
本文介绍了Docker-Compose在启动使用CREATE-REACT-APP创建的Reaction应用程序后立即停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用create-react-app工具创建一个Reaction应用程序,如here所述。

我想使用docker-compose在停靠容器中运行Reaction应用程序。我采取了以下步骤:

在我的计算机上,我创建了一个目录调用app并运行了NodeJS停靠容器:

mkdir app
docker run -it --rm -v "$(pwd)/app:/app" -w /app -p 3000:3000 node:13.10.1 bash

在容器中,我初始化Reaction应用程序并启动应用程序:

npx create-react-app .
yarn start

在浏览器中打开http://localhost:3000/#/时可以看到默认的反应页。

接下来,我停止yarn start并退出容器。

在我的计算机上,我可以通过运行以下命令来启动Reaction应用程序:

docker run -it --rm -v "$(pwd)/app:/app" -w /app -p 3000:3000 node:13.10.1 yarn start

再次在浏览器中打开http://localhost:3000/#/时可以看到默认的反应页面。

接下来,我通过停止停靠容器来停止Reaction应用程序。

最后,我创建了以下docker-compose.yml文件:

version: '3.7'
services:
    test-create-react-app:
        image: node:13.10.1
        volumes:
            - ./app:/app
        working_dir: /app
        ports:
            - 3000:3000
        command: ["yarn", "start"]

当我使用docker-compose启动停靠容器时,容器会启动,然后立即停止:

➜  test-create-react-app docker-compose up
Creating network "test-create-react-app_default" with the default driver
Creating test-create-react-app_test-create-react-app_1 ... done
Attaching to test-create-react-app_test-create-react-app_1
test-create-react-app_1  | yarn run v1.22.0
test-create-react-app_1  | $ react-scripts start
test-create-react-app_1  | ℹ 「wds」: Project is running at http://172.21.0.2/
test-create-react-app_1  | ℹ 「wds」: webpack output is served from 
test-create-react-app_1  | ℹ 「wds」: Content not from webpack is served from /app/public
test-create-react-app_1  | ℹ 「wds」: 404s will fallback to /
test-create-react-app_1  | Starting the development server...
test-create-react-app_1  | 
test-create-react-app_1  | Done in 1.31s.
test-create-react-app_test-create-react-app_1 exited with code 0

有人能解释一下使用docker-compose启动Docker容器时应用程序停止的原因吗?

下面是一些可能帮助您发现问题的版本:

Docker版本:

➜  test-create-react-app docker version
Client:
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        369ce74a3c
 Built:             Fri Feb 28 23:45:43 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       369ce74a3c
  Built:            Wed Feb 19 01:06:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.3-0ubuntu1~18.04.1
  GitCommit:        
 runc:
  Version:          spec: 1.0.1-dev
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit:

Docker编写版本:

➜  test-create-react-app docker-compose version
docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Reaction应用程序包:

➜  test-create-react-app cat app/package.json
{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "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": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

推荐答案

stdin_open: true添加到Docker-Compose文件为我解决了问题。这是在相应的github issue中建议的。

这篇关于Docker-Compose在启动使用CREATE-REACT-APP创建的Reaction应用程序后立即停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆