Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Docker container exiting immediately after starting when using npm init react-app

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

> mytest@0.1.0 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

over 4 years ago · Santiago Trujillo
9 Respostas
Responde à pergunta

0

So nothing is wrong with the setup turns out there is an open issue for this.

https://github.com/facebook/create-react-app/issues/8688

Downgrading to 3.4 solves for now

over 4 years ago · Santiago Trujillo Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório

0

docker run -it -p 80:3000 imagename resolve my problem.

over 4 years ago · Santiago Trujillo Relatório

0

Running the command with -it worked for me:

docker run -it -p 3001:3000 Imageid
over 4 years ago · Santiago Trujillo Relatório

0

Ran into the same issue. -it flag resolved the issue.

docker run -it -p 3001:3001 <image-id>
over 4 years ago · Santiago Trujillo Relatório

0

I got the same issue as you and just ran the above command to fix it:

sudo docker run -it -p 3001:3000 Image-Name

Hope it helps

over 4 years ago · Santiago Trujillo Relatório

0

I solve the problem. Inside package.json replace "react-scripts": "3.4.1" to "react-scripts": "3.4.0"

Then rebuild image and It works ! They mess up something with react-scripts": "3.4.1" Just use version 3.4.0

over 4 years ago · Santiago Trujillo Relatório

0

You can use the below with -itd flag as well.

sudo docker run -itd -p 3001:3000 Image-Name
over 4 years ago · Santiago Trujillo Relatório

0

Using the suggestion mentioned in this ans. on stackoverflow and on github, of adding

ENV CI=true to the Dockerfile before CMD ["npm", "run", "start"], worked.

I'm not sure why this works. It may have something to do with this point. You can read more about the env CI=true in the react docs.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda