docker - 使用 docker-compose up 运行的 React 应用程序没有得到任何响应
问题描述
Compiled successfully!
web_1 |
web_1 | You can now view react-docker-app in the browser.
web_1 |
web_1 | Local: http://localhost:3000
web_1 | On Your Network: http://172.18.0.2:3000
web_1 |
web_1 | Note that the development build is not optimized.
web_1 | To create a production build, use yarn build.
web_1 |
运行 docker-compose up 给出了上面的输出,但是当我尝试在浏览器上连接到服务器时,我什么也没得到:
The server at 172.18.0.2 is taking too long to respond.
Firefox can’t establish a connection to the server at localhost:3000.
我输入了端口和地址:
http://172.18.0.2:3000/
http://localhost:3000/
我没有收到任何错误消息。我正在使用我用 npx create-react-app docker-app 创建的样板项目。
有什么不对。
这是我的码头文件:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
stdin_open: true
tty: true
volumes:
- /app/node_modules
- .:/app
Dockerfile.dev:
FROM node:11.10.1-alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
解决方案
我可以看看你的 Dockerfile.dev 吗?
它应该看起来像这样:
FROM node:13
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
推荐阅读
- javascript - 净::ERR_CONTENT_LENGTH_MISMATCH 200(好的)
- c# - 在 list<> 中添加一个类并再次复制该类并通过一些修改再次添加
- android - Google Play 中的 java.lang.RuntimeException - 不知道如何分析
- firebase - Flutter Firestore 查询 2 个集合
- javascript - Google GeoChart 缺少区域
- python - 使用 tensorflow 的多语言通用句子编码器的问题
- javascript - 将两个文件上传到 Node 服务器并使用 ajax 接收回一个文件
- c++ - 如何使用 using 而不是 define 或其他 C++ 功能?
- r - 在 Shiny 中将 ggplot 生成的散点图保存为 PDF 文件,无需保存额外文件
- python-3.x - Heroku 上部署的 Dash 应用程序无法读取 CSV 文件