我有一个simple dockerized flask backend侦听0.0.0.0:8080
,并且simple dockerized react frontend向localhost:8080/api/v1.0/resource
发送请求。现在,我想在docker中运行这些容器,然后将请求发送到服务名称backend
撰写文件如下所示:
version: '3'
services:
backend:
ports:
- "8080:8080"
image: "tobiaslocker/simple-dockerized-flask-backend:v0.1"
frontend:
ports:
- "80:80"
image: "tobiaslocker/simple-dockerized-react-frontend:v0.1"
用于请求NGINX
的localhost
配置:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
前端发送请求axios.get('http://localhost:8080/api/v1.0/resource')
我的问题:
NGINX
才能使用服务名称(例如backend
)我不确定从前端发送请求并发现难以调试时,proxy_pass
将如何生效。
问候
您不需要nginx,因为这些图像已在单独的端口中提供。您的前端可以通过http://localhost:8080
轻松找到后端api,因为它在端口8080
上运行。