首页 > 解决方案 > 如何在 MS Azure 上托管 docker-compose 应用程序?

问题描述

我想将容器化的 Web 应用程序部署到 MS Azure。因此,我编写了以下 docker-compose 文件:

version: "3"
services:
    frontend:
        image: fitnessappcontainerregistry.azurecr.io/crushit:frontend
        build:
            context: ./frontend
            dockerfile: Dockerfile
        networks:
            - crushit
        ports:
            - "80:3000"
        restart: unless-stopped

    wikihow:
        image: fitnessappcontainerregistry.azurecr.io/crushit:backend-wikihow
        build:
            context: ./backend
            dockerfile: ./services/WikiHow Service/Dockerfile
        networks:
            - crushit
        restart: unless-stopped

    training:
        image: fitnessappcontainerregistry.azurecr.io/crushit:backend-training
        build:
            context: ./backend
            dockerfile: ./services/Training Service/Dockerfile
        networks:
            - crushit
        restart: unless-stopped

    eventpublisher:
        image: fitnessappcontainerregistry.azurecr.io/crushit:backend-eventpublisher
        build:
            context: ./backend
            dockerfile: ./services/EventPublisher/Dockerfile
        networks:
            - crushit
        restart: unless-stopped

    accountservice:
        image: fitnessappcontainerregistry.azurecr.io/crushit:backend-account
        build:
            context: ./backend
            dockerfile: ./services/Account Service/Dockerfile
        networks:
            - crushit
        restart: unless-stopped
    proxy:
        image: fitnessappcontainerregistry.azurecr.io/crushit:backend-proxy
        build:
            context: ./backend
            dockerfile: ./proxy/Dockerfile
        networks:
            - crushit
        ports:
            - "5000:5000"
        restart: unless-stopped
networks:
    crushit:
        driver: bridge

要使应用程序正常运行,必须将两个容器(前端、代理)暴露给外部。此外,所有容器都必须能够相互通信(因此我为所有服务添加了自定义网络)。所有容器映像都存储在 Azure 容器注册表中。现在我想知道如何在 Azure 上托管我的应用程序。我已经尝试过“Web App for Containers”,这与我认为的“App Services”相同。这并没有完全奏效,因为我无法公开像 5000 这样的“非标准”端口。有没有其他方法可以使用这个 docker-compose 文件在 Azure 上托管我的应用程序,或者我必须使用 Kubernetes 代替吗?

标签: azuredockerdocker-composeazure-web-app-service

解决方案


可以使用 docker-compose.yml 文件在 Azure Web App for container 中部署容器。还有一些你需要知道的。

首先,Azure Web App 只能对外暴露一个端口。所以这意味着你只能将一个容器暴露在外面,而不是两个。

其次,如果你暴露了 80 或 443 以外的端口,那么你可以使用环境变量WEBSITES_PORT让 Azure 知道。是文档。

第三,Web App只支持docker-compose的部分选项,这里可以看到支持的选项和不支持的选项。

最后一个是Web App中的所有容器都可以通过容器暴露的端口相互通信。所以你不需要设置network选项。


推荐阅读