简体   繁体   中英

Docker container with NodeJs is self shutting down on Window

I have a bit of a problem with the NodeJS that is shutting down after a few seconds from the moment the run command had started to execute.

For a start, I had created a react project by running the command create-react-app <my_project_name> . After this, in the project folder, I had created a docker file named Dockerfile.dev. that looks like:

FROM node:alpine

WORKDIR '/app'

COPY package.json .
RUN npm install
COPY . .

CMD ["npm", "run", "start"]

And compiled it with the command docker build -f Dockerfile.dev -t emy. The build was a success, but when it had come to run it with the command docker run -p 127.0.0.1:3000:3000 emy . The container is self shutting down after a few seconds.

This is the structure of the generated project: 在此处输入图像描述

And the output of the docker running command for git bash terminal : 在此处输入图像描述 And for the window terminal : 在此处输入图像描述

The container exit code is 0. So it's normal...

Steps to reproduce the problem :

1) Install NodeJS .

2) Install react project generator .

3) Create a project by running the command create-react-app <my_project_name> in the window terminal.

4) Step into the newly created project, with cd <my_project_name>

5) Create Docker file with the content that you can find above.

6) Build the container by running the command docker build -t emy.

7) Now let's reproduce the problem by running the container with the command docker run -p 127.0.0.1:3000:3000 emy

8) Wait 5 seconds (max) and you should have the same problem us me.

The solution to this problem is to add "it" argument to the docker run command. For git bash terminal : 在此处输入图像描述

and for window terminal : 在此处输入图像描述 Hope this will help others

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM