docker - nginx:在 /etc/nginx/conf.d/default.conf 的上游“api:5000”中找不到 [emerg] 主机
问题描述
我已经搜索了几个小时,但找不到根本问题原因。这是我的 docker-compose.yml 文件,您可以在下面看到:
version: "3"
services:
postgres:
image: "postgres:latest"
environment:
- POSTGRES_PASSWORD=postgres_password
redis:
image: "redis:latest"
nginx:
restart: always
build:
dockerfile: Dockerfile
context: ./nginx
ports:
- '3666:80'
depends_on:
- api
- client
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
client:
stdin_open: true
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /app/node_modules
- ./client:/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- /app/node_modules
- ./worker:/app
这是我的 nginx/default.conf
upstream client {
server client:3000;
}
upstream api {
server api:5000;
}
server {
listen 80;
location / {
proxy_pass http://client;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api
}
}
当我尝试时:#docker-compose up --build
过程中出现此错误:
nginx_1 | nginx:在 /etc/nginx/conf.d/default.conf:6 的上游“api:5000”中找不到 [emerg] 主机
解决方案
请检查您的 docker-compose 文件,您必须在 services 下设置 api
推荐阅读
- react-native - 反应原生地图折线未显示
- ios - NativeScript,播放与后台播放的其他应用程序混合的声音
- c++ - 带有类构造函数和类成员变量的意外输出值
- chart.js - 在气泡图中,如何为 X 轴传递标签 [标签将是 X 轴中的值,而不仅仅是任何文本],而不是气泡图动态计算它
- swift - 如何在 swift 4 中在 Alamofire 中发出 PUT 请求
- ios - UITableView/动态原型/自定义单元格 - 第一个单元格总是比其余单元格大?
- c# - 检查用户是否在 asp net 的每个页面中都经过身份验证
- c# - 从 itemsource 触发对象事件
- javascript - 如何使用asp.net将多个文档动态发送到whatsapp号码
- javascript - 如何使用 Javascript 在 chrome 上允许声音