代码之家  ›  专栏  ›  技术社区  ›  Atinesh

扩展docker容器时出现问题

  •  0
  • Atinesh  · 技术社区  · 6 年前

    我有一个停靠的烧瓶应用程序,其结构如下

    code_docker
    ├── docker-compose.yml
    ├── micr
    │   ├── app.py
    │   ├── Dockerfile
    │   ├── requirements.txt
    │   └── templates
    │       └── index.html
    ├── nginx
    │   ├── Dockerfile
    │   └── nginx.conf
    └── README.md
    

    nginx 作为负载均衡器,内部的代码 docker-compose.yml nginx.conf

    docker-compose.yml文件

    version: '3'
    
    services:
    
      nginx:
        container_name: nginx
        build: ./nginx
        restart: always
        deploy:
          restart_policy:
            condition: on-failure
        ports:
          - "8540:8540"
        depends_on:
          - micr
    
      micr:
        build: ./micr
        restart: always 
        deploy: 
          resources:
            limits:
              cpus: '0.50' # 50% of available processing time (CPU)
              memory: 50M  # 50M of memory
            reservations:
              cpus: '0.25'
              memory: 20M
          restart_policy:
            condition: on-failure   
        expose:
          - "8530"
        command: gunicorn -w 1 -b :8530 app:app
    

    user nginx;
    
    worker_processes 4;
    
    events {
        worker_connections 1024;
    }
    
    http {
        keepalive_timeout 15;
    
        server {
            listen 8540;
            server_name localhost;
    
            location / {
                proxy_pass http://localhost:8530;
                #proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forward-Host $server_name;
            }
        }
    }
    

    我可以发出下面的命令来缩放容器,从 message

    docker-compose up --scale micr=4
    

    但是当我试图访问它们时,我得到了这个错误

    enter image description here

    0 回复  |  直到 6 年前
        1
  •  1
  •   Artemiy Rodionov    6 年前
    • 您需要为Nginx和代理容器创建一个网络。有关详细信息,请参见 this .
    services:
      nginx:
        networks:
          - proxy
        ...
    
      micr:
        networks:
          - proxy
        ...
    
    networks:
      proxy:
    
    • 如此确定 proxy_pass http://micr:8530
    • this 详细情况