我无法运行我的reactjs应用程序的Docker容器 [英] I can't run a docker container of my reactjs app
问题描述
我是docker的新手,我试图运行一个create-react-app图像容器,所以这是我已经完成的步骤:
I'm new with docker and i tried to run a container of create-react-app image so this is the steps that i have done :
1- npx create-react-app前端
1- npx create-react-app frontend
2-我创建了一个如下所示的Dockerfile.dev:
2- I created a Dockerfile.dev like below:
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD ["npm" , "run" , "start"]
3- I使用此命令来构建映像:
3- I used this command to build the image :
docker build -f Dockerfile.dev .
4-当我使用提供的图像ID运行容器时:
4- When i run the container using the image id provided :
docker run -p 3000:3000 my_docker_image_id
屏幕截图中未显示任何内容:
Nothing happens as provided in the screen shot :
但是当我在命令中添加-i参数时,一切正常:
But when i add -i argument to my command everything works fine :
docker run -p 3000:3000 -i my_docker_image_id
有什么想法吗?
推荐答案
react-scripts 3.4.1版本存在问题,
There is an issue with the version 3.4.1 of react-scripts,
所以我添加了一个docker-compose文件,我指定了这一行来解决问题并保存我的一天:
So i added a docker-compose file and i specified this line who solve the problem and save my day :
stdin_open: true
所以我的码头工人mpose.yml文件如下所示:
So my docker-compose.yml file looks like this :
version : '3'
services:
web:
build:
context: .
dockerfile: Dockerfile.dev
stdin_open: true
ports:
- "3000:3000"
volumes:
- /app/node_modules
- .:/app
这篇关于我无法运行我的reactjs应用程序的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!