2016-09-06 55 views
0

我一直在關注如何使用docker-compose和nginx製作負載均衡應用程序的tutorial。然而,我的負載平衡器/協調器不工作 - 我想要做的是讓nginx接受請求並將它們分成三個工作者,並且我希望nginx和三個工作者在不同的碼頭容器中運行,但是我得到跟隨錯誤。我的compilerwebservice_worker確實可以正常工作,並且我可以在docker ps中看到所有這三個,並且我可以在他們正在監聽的localhost帖子上使用wget來ping它們。使用Docker Compose啓動NGINX負載均衡器

該錯誤消息

$ docker-compose up 
Starting compilerwebservice_worker1_1 
Starting compilerwebservice_worker3_1 
Starting compilerwebservice_worker2_1 
Starting compilerwebservice_nginx_1 
Attaching to compilerwebservice_worker1_1, compilerwebservice_worker3_1, compilerwebservice_worker2_1, compilerwebservice_nginx_1 
nginx_1 | 2016/09/06 07:17:47 [emerg] 1#1: host not found in upstream "compiler-web-service" in /etc/nginx/nginx.conf:14 
nginx_1 | nginx: [emerg] host not found in upstream "compiler-web-service" in /etc/nginx/nginx.conf:14 
compilerwebservice_nginx_1 exited with code 1 

NGINX配置

http { 
    upstream compiler { 
     least_conn; 
     server worker1:4567; 
     server worker2:4567; 
     server worker3:4567; 
    } 

    server { 
     listen 4567; 
     location/{ 
       proxy_pass http://compiler; 
       proxy_http_version 1.1; 
       proxy_set_header Upgrade $http_upgrade; 
       proxy_set_header Connection 'upgrade'; 
       proxy_set_header Host $host; 
       proxy_cache_bypass $http_upgrade; 
     } 
    } 
} 

我多克爾-撰寫文件

nginx: 
    build: ./src/main/nginx 
    links: 
     - worker2:worker2 
     - worker3:worker3 
     - worker1:worker1 
    ports: 
     - "4567:4567" 

worker1: 
    build: . 
    ports: 
     - "4567" 

worker2: 
    build: . 
    ports: 
     - "4567" 

worker3: 
    build: . 
    ports: 
     - "4567" 

NGINX泊塢文件

# Set nginx base image 
FROM nginx 

# Copy custom configuration file from the current directory 
COPY nginx.conf /etc/nginx/nginx.conf 

回答

0

我需要具有配置更改之間docker-compose build重建。當我更改應用程序的名稱時,錯誤消息指出了一個服務器,其名稱是我選擇的原始服務器,而不是我一直在更改的服務器。