azure - 如何在 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 代替吗?
解决方案
可以使用 docker-compose.yml 文件在 Azure Web App for container 中部署容器。还有一些你需要知道的。
首先,Azure Web App 只能对外暴露一个端口。所以这意味着你只能将一个容器暴露在外面,而不是两个。
其次,如果你暴露了 80 或 443 以外的端口,那么你可以使用环境变量WEBSITES_PORT
让 Azure 知道。这是文档。
第三,Web App只支持docker-compose的部分选项,这里可以看到支持的选项和不支持的选项。
最后一个是Web App中的所有容器都可以通过容器暴露的端口相互通信。所以你不需要设置network
选项。
推荐阅读
- tensorflow - keras load_model 无法识别新的 AUC 指标 tf.keras.metrics.AUC()
- c# - 让相机在没有相机胶卷的情况下统一跟随球
- javascript - vb.net 这是反射吗
- fortran - Fortran if 显示全部且未选中
- linux - 核心转储未生成
- javascript - 发送到 PHP 时如何处理已发布的 multipart/form-data?
- c++ - 缓冲区参数为 NULL
- php - 如何调整openssl证书位置
- azure-functions - Azure 功能应用程序设置以选择生产、暂存和开发以外的环境
- javascript - OpenCV在python和javascript之间调整了大不相同的结果