如何解决无法连接到docker-compose中的其他容器
我尝试了nginx +反应前端与带有以下docker-compose.yml
的gunicorn +烧瓶后端进行对话
version: '3.8'
services:
ner:
build: ./src_python
command: gunicorn --bind 0.0.0.0:5000 server:app --preload
expose:
- 5000
frontend:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
stdin_open: true
depends_on:
- ner
前端的Dockerfile
FROM node:14-alpine3.12 AS build_stage
WORKDIR /
COPY package.json package-lock.json ./
RUN npm install
COPY src ./src
COPY public ./public
RUN npm run build
FROM nginx:alpine
COPY --from=build_stage /build/ /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
nginx配置
server {
listen 80;
location / {
index index.html;
root /usr/share/nginx/html;
}
location /api/v1 {
proxy_pass http://localhost:5000/api/v1;
}
location /api/v2 {
proxy_pass http://localhost:5000/api/v2;
}
}
但是,在运行时,我在docker-compose的日志流中看到了以下内容
frontend_1 | 2020/08/19 13:57:36 [error] 29#29: *4 connect() failed (111: Connection refused) while connecting to upstream,client: 172.19.0.1,server:,request: "GET /api/v2?query=watch%20harry%20potter%20vs%20read%20harry%20potter HTTP/1.1",upstream: "http://127.0.0.1:5000/api/v2?query=watch%20harry%20potter%20vs%20read%20harry%20potter",host: "localhost",referrer: "http://localhost/?query=watch%20harry%20potter%20vs%20read%20harry%20potter"
我怀疑我错误地配置了nginx或前端,因为docker logs -f backend_container_id
没有显示任何拒绝连接的信息。
如果有帮助,请参见以下package.json摘录
{
"name": "short_text_understand","version": "0.1.0","private": true,"homepage": ".","dependencies": {
...
},"scripts": {
...
},"eslintConfig": {
"extends": "react-app"
},"proxy": "http://localhost:5000","browserslist": {
"production": [
...
],"development": [
...
]
},"devDependencies": {
...
}
}
我该如何解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。