在退出代码为0的Docker容器中退出的React应用 [英] React app exiting in docker container with exit code 0

查看:122
本文介绍了在退出代码为0的Docker容器中退出的React应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用nginzx,flask和react创建一个docker-compose安装程序.我以react-create-app( https://github.com/facebook/create-react-app ),并且尚未对其进行任何更改.

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.

我的react应用程序的Dockerfile是:

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"]

撰写脚本为:

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:

烧瓶和nginx容器启动正常,react的输出为:

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

推荐答案

在我的docker-compose文件中添加:stdin_open: true解决了我的问题.

Adding: stdin_open: true to my docker-compose file fixed my issue.

这篇关于在退出代码为0的Docker容器中退出的React应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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