Azure 容器实例:从 Django+Nginx+Postgres 创建多容器组

Azure Container Instances: Create a multi-container group from Django+Nginx+Postgres

我已经 docker使用 Postgres、Gunicorn 和 Nginx 完成了一个 Django 项目 this tutorial

现在我想将应用程序移动到 azure 容器实例。我可以简单地在 this tutorial 之后创建一个容器组,并期望容器映像以正确的方式通信吗?

我在本地使用 运行 项目 docker-compose -f docker-**compose.prod.yml** up -d --build 但是如何在 Azure 容器实例中处理容器之间的通信?

docker-compose.prod.yml 看起来像这样:

version: '3.7'

services:
  web:
    build:
      context: ./app
      dockerfile: Dockerfile.prod
    command: gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
    volumes:
        - static_volume:/home/app/web/staticfiles
        - media_volume:/home/app/web/mediafiles
    expose:
        - 8000
    env_file:
        - ./.env.prod
    depends_on:
        - db
  db:
    image: postgres:12.0-alpine
    volumes:
        - postgres_data:/var/lib/postgresql/data/
    env_file:
        - ./.env.prod.db
  nginx:
    build: ./nginx
    volumes:
        - static_volume:/home/app/web/staticfiles
        - media_volume:/home/app/web/mediafiles
    ports:
        - 1337:80
    depends_on:
        - web

volumes:
  postgres_data:
  static_volume:
  media_volume:

容器将能够使用服务名称(web、db、nginx)相互通信,因为它们是容器组本地网络的一部分。另外,看看 documentation as you can't use docker-composes file directly unless you use the edge version of Docker Desktop.

另一方面,重新启动后,您将丢失存储在卷中的所有内容,因为您没有使用某种外部存储。看看 documentation.