Problem
When starting a Docker container with a React app inside by performing the following command:
docker run -p 3000:3000 [my-container-id]
Your React app may exit immediately with the output like this:
goodman@Mac-mini client % docker run -p 3000:3000 33c988fb2142
> [email protected] start /app
> react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.2/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
goodman@Mac-mini client %
This error is not on your side but caused by recent updates of the create-react-app library.
Solution
The solution is quite simple. All you need to do is just add the -it flag to your command:
docker run -it -p 3000:3000 [container-id]
In my case:
docker run -it -p 3000:3000 33c988fb2142
Further reading:
- Best Libraries for Formatting Date and Time in React
- Docker: How to Name or Rename a Container
- React + TypeScript: Making a Custom Context Menu
- React: “I agree to terms” checkbox example
- React + TypeScript: Create an Autosize Textarea from scratch
You can also check our React category page and React Native category page for the latest tutorials and examples.