[英]React app set proxy not working with docker compose
I am trying to use the docker compose to build two containers:我正在尝试使用 docker compose 来构建两个容器:
I docker composed them up and both of them were boosted up.我 docker 将它们组合起来,并且它们都得到了提升。 When I visited the react, it supposed to proxy the request from the react app with port 3000 to flask server with port 5000. But I encountered this:
当我访问react时,它应该将来自react应用程序的3000端口的请求代理到5000端口的flask服务器。但我遇到了这个:
frontend_1 | Proxy error: Could not proxy request /loadData/ from localhost:3000 to http://backend:5000.
frontend_1 | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
which I figure means it still does not know the actual IP address of the backend container.我认为这意味着它仍然不知道后端容器的实际 IP 地址。
Here are some configurations:下面是一些配置:
docker-compose.yml docker-compose.yml
version: "3"
services:
backend:
build: ./
expose:
- "5000"
ports:
- "5000:5000"
volumes:
- .:/app
command: gunicorn server:app -c ./gunicorn.conf.py
networks:
- app-test
frontend:
build: ./frontend
expose:
- "3000"
ports:
- "3000:3000"
volumes:
- ./frontend:/app
networks:
- app-test
depends_on:
- backend
links:
- backend
command: yarn start
networks:
app-test:
driver: bridge
backend Dockerfile后端 Dockerfile
FROM python:3.7.3
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
frontend Dockerfile前端 Dockerfile
FROM node:latest
WORKDIR /app
COPY . /app
gunicorn.conf.py gunicorn.conf.py
workers = 5
worker_class = "gevent"
bind = "127.0.0.1:5000"
frontend package.json前端 package.json
{
"proxy": "http://backend:5000",
}
I tried nearly everything said online, and it just does not proxy the request.我几乎尝试了网上所说的所有内容,但它只是不代理请求。
Some information I have already known:我已经知道的一些信息:
Anyone could help me?任何人都可以帮助我吗?
Thanks in advance!提前致谢!
尝试在 gunicorn conf 中将bind = "0.0.0.0:5000"
更改为bind = "0.0.0.0:5000"
并将后端服务中的端口相应地更改为"127.0.0.1:5000:5000"
(最后一个是可选的)
By changing gunicorn.conf.py with通过改变gunicorn.conf.py与
bind = "0.0.0.0:5000"
fixed my problem.解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.