使用npm init react-app启动后,Docker容器立即退出 [英] Docker container exiting immediately after starting when using npm init react-app
问题描述
我正在尝试使用react项目启动Docker容器,该项目是使用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.
这是我的Docker文件
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。
成功创建一个映像(带有很多npm警告),然后当我运行 Docker run< image>
时,在我的终端机中输出
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...
很快就会出现启动开发服务器...
,它在我的终端中停止运行了。如果我检查 Docker ps
我看不到任何容器在运行,如果我运行 Docker ps -a
我可以看到一个容器已启动,然后立即退出。
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日志
显示上面的终端输出,任何人都遇到这种情况?仅在我的npm init react-app项目中,我的其他nodejs + express项目在完全相同的docker文件下运行良好
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
推荐答案
我尝试降级,但是没有用。对我有用的是我添加的react应用程序部门中的 docker-compose
文件:
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
此处也建议使用此解决方案:在github上发布
This solution is also suggested here: issue on github
这篇关于使用npm init react-app启动后,Docker容器立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!