【问题标题】:How to access Azure App Service application log to check Docker Compose errors?如何访问 Azure App Service 应用程序日志以检查 Docker Compose 错误?
【发布时间】:2020-02-16 14:08:06
【问题描述】:

我是 Azure 的新手,这是我在 StackOverflow 上的第一个问题。我在使用 Docker Compose 使用多容器 Docker (Linux) 部署新的 Azure 应用服务时遇到问题。不幸的是,我无法访问我的应用程序日志,因为存在未知错误。我只更改配置以使用我的私有注册表和docker-compose 配置,其他设置保持默认。我正在使用 Azure for Students 计划,因此无法选择加入 1:1 专家支持。

我的应用服务基本上由 4 个容器组成:webservice (Django REST Framework)、comprof (VueJS)、raspisample (Express) 和 db (PostgreSQL)。我正在使用 GitLab 的 Docker Registry (registry.gitlab.com),它是一个私有注册表(图像不公开)。这是我的docker-compose.yml 文件。

version: '3'

services:
  webservice:
    image: registry.gitlab.com/something/webservice:latest
    restart: always
    working_dir: /opt/webservice
    environment:
      - DEBUG=false
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
      - PREDICTOR_URL=https://something-predictor.azurewebsites.net
      - CACHE_DIR=/var/cache
      - SECRET_KEY="**omitted**"
      - LOG_DIR=/var/log/webservice
      - UPLOADS_DIR=/var/uploads
      - ACCESS_LOG=/var/log/webservice/access_main.log
      - ERROR_LOG=/var/log/webservice/error_main.log
    ports:
      - "81:80"
    volumes:
      - webservice_data:/var/log/webservice
      - webservice_data:/var/cache
      - webservice_data:/var/uploads
    depends_on:
      - db
    networks:
      internal:
  comprof:
    image: registry.gitlab.com/something/company-profile:latest
    restart: always
    working_dir: /opt/comprof
    environment:
      - WEBSERVICE_URL=http://webservice:81
      - RASPI_SAMPLE_URL=http://raspisample:82
      - PREDICTOR_URL=https://something-predictor.azurewebsites.net
      - ACCESS_LOG=/var/log/comprof/access_main.log
      - ERROR_LOG=/var/log/comprof/error_main.log
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - comprof_data:/var/log/comprof
    depends_on:
      - webservice
    networks:
      default:
      internal:
  raspisample:
    image: registry.gitlab.com/something/local-webservice:latest
    restart: always
    working_dir: /opt/sample
    environment:
      - WEBSERVICE_URL=http://webservice
      - ACCESS_LOG=/var/log/raspi/access_main.log
      - ERROR_LOG=/var/log/raspi/error_main.log
    ports:
      - "82:3000"
    volumes:
      - raspisample_data:/var/log/raspi
    networks:
      internal:
  db:
    image: postgres
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    volumes:
      - db_data:/var/lib/postgresql/data
    networks:
      internal:

networks:
  default:
  internal:
    internal: true

volumes:
  webservice_data:
  raspisample_data:
  comprof_data:
  db_data:

docker-compose 配置仅在我的 Azure 应用服务中失败。我的大学里有另一个虚拟机,这个配置在那里工作得很好。我也试过在我自己的笔记本电脑上,它也可以正常工作。在 Azure 中,错误消息如下:

:( Application Error
If you are the application administrator, you can access the diagnostic resources.

Azure Error Message (Picture)

当我尝试在应用设置 > 容器设置 > 日志中解决此问题时,它显示了这一行错误:

Error in retrieving logs.

通过 Log Streams 访问日志时,我也检索到相同的错误。我在应用服务日志菜单上启用了应用程序日志,但它没有任何效果。我也无法访问 Azure 建议的 Docker 日志链接,它只会永远加载并在加载 15 分钟后返回连接超时错误。

问题是:我的docker-compose.yml 有什么问题吗?或者我的 Azure 应用服务的配置有什么问题吗?谢谢。

【问题讨论】:

  • 您的应用服务使用哪个操作系统? linux还是windows?
  • 你的项目使用什么语言?
  • @BowmanZhu 我正在使用 Linux。我对webservice 使用Python (Django),对comprofraspisample 使用JavaScript (Node/Vue.js)。在comprof,我也使用 Nginx。
  • 您好,我遇到了类似的问题。你有没有得到任何地方?
  • 在 linux 容器上运行的 Java 应用程序也是如此

标签: docker-compose azure-web-app-service docker-container


【解决方案1】:

要在使用 docker-compose.yml 时访问您的容器日志,您必须访问

https://.scm.azurewebsites.net/api/logs/docker

对于每个容器,您都会获得一个 JSON 对象,其中包含相应日志文件的 URL:

[
   {
      "machineName":"RD00XYZYZE567A",
      "lastUpdated":"2018-05-10T04:11:45Z",
      "size":25125,
      "href":"https://<app-name>.scm.azurewebsites.net/api/vfs/LogFiles/2018_05_10_RD00XYZYZE567A_docker.log",
      "path":"/home/LogFiles/2018_05_10_RD00XYZYZE567A_docker.log"
   }
]

复制“href”中的链接,您将获得您的日志文件。

来源:https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-multi-container-app#find-docker-container-logs

【讨论】:

  • 不幸的是,这也不起作用,它显示与我的应用程序相同的“应用程序错误”。
猜你喜欢
  • 2017-08-01
  • 1970-01-01
  • 2016-11-19
  • 2016-10-06
  • 2018-07-16
  • 1970-01-01
  • 2017-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多