【问题标题】:Azure Containers Docker Compose (preview) issue listening on port 8080Azure Containers Docker Compose(预览版)问题监听端口 8080
【发布时间】:2021-07-12 10:26:38
【问题描述】:

我想在 Azure Web Apps for Containers 上使用 Docker Compose 部署 Angular-based app

我已经在我们的私有存储库上创建了应用程序的自定义映像,这里是 Docker Compose 文件的修改版本

version: '3.8'
services:
  cnil-pia-back:
    container_name: pia-back
    image: example.azurecr.io/cnil-pia/pia-backend:latest
    restart: unless-stopped
    environment:
      DATABASE_HOST: 'database'
      DATABASE_USERNAME: 'postgres'
      DATABASE_PASSWORD: 'somepassword' # Please don't mind, we are testing for now
      SECRET_KEY_BASE: 'somesecret'
    links:
      - database
    depends_on:
      - database
    ports:
      - 8080:3000 # See comment later

  cnil-pia-front:
    container_name: pia-front
    image: example.azurecr.io/cnil-pia/pia-frontend:latest
    restart: unless-stopped
    ports:
      - 80:80

  database:
    container_name: pia-db
    image: postgres:13
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: 'somepassword'
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data: # Probably it won't work, but we are not discussing this

后端应用程序must be open to the internet, or at least firewalled。无论如何,Angular 从浏览器调用后端,因此前端应用程序(服务 Angular 静态资源)和后端应用程序都必须可以从浏览器访问。

问题在于,目前使用所选 DNS 名称的客户端无法访问端口 8080 或 3000,而 Angular 应用程序可以。

我从Azure documentation 了解到,Docker Compose 支持有一些限制,包括仅支持端口 8080 和 80。

我希望部署两个容器,一个在前端监听 80(由 Azure 终止的 HTTPS),另一个在端口 8080 上运行良好,不管 HTTPS

这是 Docker 日志的摘录

2021-07-12T09:47:15.514Z INFO  -  Status: Downloaded newer image for example.azurecr.io/cnil-pia/pia-backend:latest
2021-07-12T09:47:15.522Z INFO  - Pull Image successful, Time taken: 2 Minutes and 37 Seconds
2021-07-12T09:47:15.551Z INFO  - Starting container for site
2021-07-12T09:47:15.552Z INFO  - docker run -d -p 0:3000 --name example_cnil-pia-back_0_e65f2c35 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=example-app -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=example-app.azurewebsites.net -e WEBSITE_INSTANCE_ID=acc200cd5031529803448aa52023fe967882435b7dc689afd8df4117b5572ca3 example.azurecr.io/cnil-pia/pia-backend:latest  

注意,Azure Docker 引擎在-p 选项中任意使用0 作为监听端口。

问题是:如果可能的话,我如何在 Azure 上使用 Docker Compose 公开两个容器?

【问题讨论】:

    标签: azure docker docker-compose


    【解决方案1】:

    该功能处于预览阶段,每个 Docker Compose 堆栈仅支持暴露本地端口 80,该端口由 Azure 进行 TLS 终止。

    这意味着外部只能访问堆栈中的一项服务。如果前端层内部调用后端(例如服务器页面技术),则可以部署 3 层服务。 如果后端必须通过互联网公开,则它必须单独部署。可以在另一个 Docker Compose 堆栈中,也可以作为单个容器

    【讨论】:

      猜你喜欢
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 1970-01-01
      • 2012-08-11
      • 2022-11-12
      • 1970-01-01
      相关资源
      最近更新 更多