Resolving "react exit with code 0" when running a React container
I guess before running into this error on your Docker instance I presume you have basic knowledge of Docker and as such won't need to explain or give basic explanation about Docker and rather go straight to the solution of the aforementioned problem.
The Error
The error is met when you run the below command on a set of project(s) 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 😉
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 be executed 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, Downgrade your "react scripts" version to 3.4.0
NOTE: Downgrading to 3.3.0 or lower wont solve this error and might bring up other issues on your react project
"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
},
Top comments (6)
Hi,I am running a React App in ECS .The docker image has been created and pushed to ECR through jenkins pipeline.The ECS container gets created through terraform code. But the container gets exited with code 0 and new one starts.This became a loop.When i try creating a container manually with commands from the same image,then the container remains active.
When i check the logs from cloudwatch i get the logs as
content not from webpack is served from /app/public
404s will fallback to /
Can i get some help on this?
Have you tried making the changes as stated in the post to your Docker file?
For me its is because of version for the Node.js I downgrade from v17+ to v16+ and its works just fine. Here I read the discussions from stackoverflow.com/questions/696928... . Then I change my Dockerfile config using node:16 and its works just fine after that. I'm not sure why.
Option 2 works for me . Thank you!
Thank you! Option 3 doesn't work for me but option 5 does~
Related GitHub issue: github.com/facebook/create-react-a...