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.
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.
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
react:
tty: true //NOTE
build: dockerreact
ports:
- "3000:3000"
Option 2
(While Running Multiple Containers)
Setting "stdin_open:true" to your react instance
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
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
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.
"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
},
Aiko AI: The Agent Was Easy, the Diff Was Not
Wiring three LLM agents into a plan-write-verify loop took an afternoon. Getting their output to actually apply to a file took considerably longer.
pack.nvim: Neovim 0.12 Made Half of It Dead Code
Neovim 0.12 shipped native package management. Every plugin manager on the market was still carrying a git implementation it no longer needed.