Docker container exiting immediately after starting when using npm init react-app

Jason McFarlane picture Jason McFarlane · Mar 21, 2020 · Viewed 7.5k times · Source

I am trying to start a Docker container with a react project, the project is created using npm init react-app.

This is my docker file

# Specify a base image
FROM node:alpine

WORKDIR /usr/app

# Install some depenendencies
COPY ./package.json ./
RUN npm install
COPY ./ ./

# Default command
CMD ["npm", "run", "start"]

Docker build . creates an image successfully (with a lot of npm warnings) and then when I run Docker run <image> this is the output in my terminal

> [email protected] start /usr/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 /usr/app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...

Soon as it hits Starting the development server... it stops running in my terminal. If I check Docker ps I can see no containers are running, if I run Docker ps -a I can see a container was started up and then exited immediately.

Docker logs shows the terminal output above, anybody run into this situation? Its only with my npm init react-app project, my other nodejs + express projects run fine with the exact same docker file

Answer

Ramy M. Mousa picture Ramy M. Mousa · Mar 23, 2020

I tried downgrading but it didn't work. What worked for me is in docker-compose file in the react app sector I added:

stdin_open: true

This solution is also suggested here: issue on github