我正在尝试使用 docker 运行一个 React 应用程序。这是我的步骤:
我使用创建了一个反应应用程序react-native-cli
并添加了Dockerfile.dev
文件。我的 Dockerfile.dev 文件包含以下代码:
# Specify a base image
FROM node:alpine
WORKDIR '/app'
# Install some depenendencies
COPY package.json .
RUN yarn install
COPY . .
# Uses port which is used by the actual application
EXPOSE 3000
# Default command
CMD ["yarn", "run", "start"]
然后我执行这个命令并得到这个输出。但它没有显示任何访问它的端口。
docker build -f Dockerfile.dev .
OP:成功构建ad79cd63eba3
docker run ad79cd63eba3
OP:
yarn run v1.22.4
$ 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 /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Done in 2.02s.
谁能告诉我如何启动开发服务器,它会向我显示端口,例如Http://localhost:3000
来访问它。
完整代码:https://github.com/arif2009/frontend.git https://github.com/arif2009/frontend.git
Docker 和最新版本的 React 脚本存在问题。
这是一个关于它的 Github 主题:https://github.com/facebook/create-react-app/issues/8688 https://github.com/facebook/create-react-app/issues/8688
针对您的情况的(临时且最快的)解决方案是降级 package.json 文件中的 React-scripts 版本。
从 :
"dependencies": {
...
"react-scripts": "3.4.1"
}
To :
"dependencies": {
...
"react-scripts": "3.4.0"
}
我使用此配置测试了您的项目,现在运行良好。
从上面的 Github 线程来看,这似乎是 docker-compose 的另一个解决方案和stdin_open: true
选项(基本上对应于-it
的旗帜docker run
命令。如果react-scripts版本对你很重要(并且你想保留它的最后一个版本),你也可以尝试一下
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)