Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React app exiting in docker container with exit code 0

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.

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

The compose script is:

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: 

The flask and nginx containers start fine, the output for react is:

react    |  react    | > [email protected] 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 [email protected]~start: unsafe-perm in lifecycle true react    | npm verb lifecycle [email protected]~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 [email protected]~start: CWD: /usr/src/app react    | npm info lifecycle [email protected]~poststart: [email protected] react    | npm verb exit [ 0, true ] react    | npm timing npm Completed in 1727ms react    | npm info ok  react exited with code 0 
like image 331
APorter1031 Avatar asked Mar 27 '20 23:03

APorter1031


People also ask

Why my docker run exits immediately?

Why docker container is exited immediately? You're running a shell in a container, but you haven't assigned a terminal: If you're running a container with a shell (like bash ) as the default command, then the container will exit immediately if you haven't attached an interactive terminal.

What is docker exit code1?

Exit Code 1 means that a container terminated, typically due to an application error or an invalid reference. An application error is a programming error in any code running within the container.

How do you exit the react app?

You can use Ctrl + c to stop running the React app in your command line.

How do I exit docker app?

TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl. Then the same with ctrl and d. If there's a non-shell process running, the combination is ctrl+c to interrupt it. Then you can exit the shell, or the container might exit already.


2 Answers

Adding: stdin_open: true to the React component of my docker-compose file fixed my issue.

Example:

version: '3.1'  services:     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"         stdin_open: true 
like image 93
APorter1031 Avatar answered Oct 05 '22 20:10

APorter1031


It looks like an issue with [React-Scripts] v3.4.1. Please look into this link

like image 45
sandeep reddy Avatar answered Oct 05 '22 18:10

sandeep reddy