Skip to content

visitor@igmrrf — fish-inspired shell

Type help, or pick a destination below. This is a fish-inspired website shell.

↑↓ history · Tab complete · Esc close

Back_to_Articles.log
ARTICLE_STREAM // DEV_NOTES

Resolving "react exit with code 0" when running a React container

A guide on diagnosing and fixing the common "react exit with code 0" error when running React applications inside Docker containers.

November 23, 2022 2 min read Francis Igbiriki
docker react

Alt Text So, before you'll get this error on your Docker instance I presume you have basic knowledge of Docker and as such won't need to explain but rather straight to the error and solution options.

The Error

The error is gotten when you run the below command on a set of projects that include a React App.

shell
docker-composer up

or try to start a React App container from an image on your Docker instance.

For the simplest solution, Skip to Option 5 :wink:

Option 1

(While Running Multiple Containers)

Add the configuration "tty:true" to your react instance

yaml
react:
  tty: true //NOTE
  build: dockerreact
  ports:
    - "3000:3000"

Option 2

(While Running Multiple Containers)

Setting "stdin_open:true" to your react instance

yaml
react:
  stdin_open: true //NOTE:
  build: dockerreact
  ports:
    - "3000:3000"

Option 3

(While Running Multiple Containers or Single React Container)

Add "CI=true" as a command that should run before "npm install" in your Dockerfile within your React project root directory

dockerfile
FROM node:14.5

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app

RUN CI=true //NOTE

RUN npm install
COPY . /usr/src/app

EXPOSE 3000
CMD ["npm","start"]

Option 4

(While Running Multiple Containers or Single React Container)

Use "docker-compose run" instead of "docker-compose up" as this automatically sets either option 1 or 2 as true

shell
docker-compose run

NOTE: This is only works on already built docker images

Option 5

(While Running Multiple Containers or Single React Container)

Lastly, Degrade your "react scripts" version to 3.4.0

NOTE: Degradding to 3.3.0 wont solve the error.

json
"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.0", //NOTE
    "react-scripts": "3.4.1" //NOT WORKING
},
Discussion
igmrrf/igmrrf