如何为包含卷的 Azure 容器注册表部署简单的多容器应用程序?

How to deploy simple multi-container app for Azure Container Registry containing Volumes?

我想将一个简单的多容器应用程序部署到 Azure 容器注册表。我面临的问题是,

在这种情况下我有什么选择?我正在关注官方 Azure tutorial 将我的图像推送到 ACR。

docker-compose.yml

version: "3.7"

services:
  web:
    build: .
    image: flask-app
    container_name: flask-app
    ports:
      - "5000:5000"
    volumes:
      - code:/code
    depends_on:
      - redis
  redis:
    image: redis

volumes:
  code:
    driver: azure_file
    driver_opts:
      share_name: myacishare
      storage_account_name: mystorageaccount

Dockerfile

FROM python:3.8
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py

app.py

from flask import Flask
from redis import Redis

app = Flask(__name__)
redis = Redis(host="redis", port=6379)


@app.route("/")
def hello():
    redis.incr("hits")
    return "This Compose/Flask demo has been viewed %s time(s)." % redis.get("hits")


if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)

requirements.txt

flask
redis

您不需要为 Azure 文件共享安装驱动程序。您只需按照步骤为 Windows 安装 Docker 桌面时所示设置 azure_file。它将在资源组中为您创建存储文件共享。

并且如果您使用ACR来存储您的自定义图像,那么您需要像这样登录ACR:

docker login myacr.azurecr.io -u xxxx -p xxxxx

您最好使用登录 ACR 上下文时使用的相同 Azure 帐户。请注意,您需要为该帐户分配足够的 ACR 权限。例如,AcrPull角色。