【发布时间】:2020-12-14 00:22:53
【问题描述】:
这里是 github 仓库:https://github.com/irahulsah/mutlicontainerapp 请访问它以获取更多信息,请帮助我修复此错误。
我正在使用 docker-compose 在本地运行一个多 docker 容器,这些容器是 React 前端“客户端”、一个 Nodejs 应用程序“api”,以及一个位于两个前面的 Nginx 代理。我一直在使用 docker-compose 设置,如下所示。
version: '3'
services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /usr/app/node_modules
- ./client:/usr/app
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /usr/app/node_modules
- ./server:/usr/app
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '8080:80'
我的 Nginx 设置如下
upstream client {
server client:3000;
}
upstream api {
server api:5000;
}
server {
listen 80;
server_name _;
location / {
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
proxy_pass http://client;
}
location /api {
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
}
}
最近尝试启动容器时,出现以下错误:
nginx_1 | 2019/08/08 18:11:12 [emerg] 1#1: host not found in upstream "client:3000" in /etc/nginx/conf.d/default.conf:2
nginx_1 | nginx: [emerg] host not found in upstream "client:3000" in /etc/nginx/conf.d/default.conf:2
知道为什么 nginx 找不到上游吗?
我已尝试添加指向 nginx 设置块的链接,如下所示:
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
links:
- client:client
- api:api
ports:
- '8080:80'
我也尝试了“depends_on”,但也得到了主机可以在客户端找到:300 错误,任何关于如何解决此错误的想法,将不胜感激。
非常感谢任何帮助或指导!!!
【问题讨论】:
-
nginx/Dockerfile.dev中有什么内容?你是如何启动整个堆栈的?后端服务是否启动成功? -
in nginx/Dockerfile.dev -> 下面的代码来自 nginx COPY ./default.conf /etc/nginx/conf.d/default.conf ,是的,后端服务器已成功启动,只有这个客户端在主机 3000 上找不到客户端,这种类型的错误即将到来......
-
更多详情:github repo链接:github.com/irahulsah/mutlicontainerapp,请帮帮我,我不知道该怎么办,我卡住了
-
我正在使用 docker-compose.yml 文件启动整个堆栈 -> sudo docker-compose up
-
为什么不使用 docker swarm 进行复制?
标签: docker docker-compose dockerfile