将容器部署到AWS存储库后,将UWSGI容器与NGINX容器[Docker]连接起来

问题描述 投票:1回答:1

Am将两个容器uwsgi和nginx部署到AWS ECS存储库。我正在使用Fargate来部署和设置容器,但在容器之间的连接和通信中出现错误。

error:No host not found in upstream "flask_app" in /etc/nginx/conf.d/nginx.conf.

Docker撰写yml文件。

version: "3"

services:
  db:
    container_name: db
    image: postgres
    restart: always
    environment:
      POSTGRES_DB: XXXXX
      POSTGRES_USER: XXXX
      POSTGRES_PASSWORD: XXXXX
    ports:
      - "54321:5432"

  flask_app:
    container_name: flask_app
    image: XXXXXXXXXXXXXXX.dkr.ecr.us-east-2.amazonaws.com/YYYYY:flask
    build:
      context: ./
      dockerfile: ./docker/Dockerfile-flask
    volumes:
      - .:/app
    depends_on:
      - db
    ports:
      - 5000:5000
    links:
      - db


  nginx:
    container_name: nginx
    image: XXXXXXXXXXXXXXX.dkr.ecr.us-east-2.amazonaws.com/YYYYY:backend
    env_file:
      - ./docker/users.variables.env
    build:
      context: .
      dockerfile: ./docker/Dockerfile-nginx
    ports:
      - 8080:80
    depends_on:
      - flask_app
    links:
      - flask_app

Nginx (nginx.conf):
server {
    listen 80;
    server_name localhost;    
    root /usr/share/nginx/html;
    location / {
        resolver 169.254.169.253;
        include uwsgi_params;
        proxy_pass http://flask_app:5000/;
        proxy_set_header Host "localhost";
    }
}


UWSGI.ini:
[uwsgi]
protocol = http
; This is the name of our Python file
; minus the file extension
module = start
; This is the name of the variable
; in our script that will be called
callable = app
master = true
; Set uWSGI to start up 5 workers
processes = 5
; We use the port 5000 which we will
; then expose on our Dockerfile
socket = 0.0.0.0:5000
vacuum = true
die-on-term = trueS

错误2019/08/23 12:27:13 [emerg] 1#1:在/etc/nginx/conf.d/nginx.conf:8的上游“ flask_app”中找不到主机。

Am将两个容器uwsgi和nginx部署到AWS ECS存储库。我正在使用Fargate来部署和设置容器,但是在容器之间的连接和通信中出现错误。 ...

amazon-web-services nginx flask docker-compose uwsgi
1个回答
0
投票

在您的示例中,您依赖于Docker compose中设置的容器名称(flask_app)与其他容器进行通信。这对于在本地环境中进行Docker撰写非常有效,但不适用于使用Fargate的ECS中。

© www.soinside.com 2019 - 2024. All rights reserved.