Azure 容器生成错误 '503' 原因 'site unavailable'

标签 azure docker docker-compose dockerfile azure-container-registry

问题

我在运行 Windows 10 的本地计算机上构建了一个 docker 镜像

  1. 正在运行 docker-compose build , docker-compose up -ddocker-compse logs -f确实生成预期结果(无错误)

  2. 通过运行 winpty docker container run -i -t -p 8000:8000 --rm altf1be.plotly.docker-compose:2019-12-17 可以正确运行应用程序

  3. 我将 Docker 镜像上传到私有(private) Azure 容器注册表

  4. 我基于 docker 镜像部署 Web 应用程序 Azure Portal > Container registry > Repositories > altf1be.plotly.docker-compose > v2019-12-17 > context-menu > deploy to web app

Azure - Deploy the web app from a docker image

  • 我运行网络应用程序并得到 The service is unavailable
  • 我的方法有什么问题吗?

    预先感谢您为此问题投入时间

    docker-compose.yml

    version: '3.7'
    services:
      twikey-plot_ly_service:
        # container_name: altf1be.plotly.docker-container-name
        build: .
        image: altf1be.plotly.docker-compose:2019-12-17
        command: gunicorn --config=app/conf/gunicorn.conf.docker.staging.py app.webapp:server
        ports:
          - 8000:8000
        env_file: .env.staging
    
    

    .env/staging

    apiUrl=https://api.beta.alt-f1.be
    authorizationUrl=/api/auth/authorization/code
    serverUrl=https://dunningcashflow-api.alt-f1.be
    transactionFeedUrl=/creditor/tx
    api_token=ANICETOKEN
    
    

    Dockerfile

    # read the Dockerfile reference documentation
    # https://docs.docker.com/engine/reference/builder
    
    # build the docker
    # docker build -t altf1be.plotly.docker-compose:2019-12-17.
    
    # https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image#use-a-docker-image-from-any-private-registry-optional
    
    # Use the docker images used by Microsoft on Azure
    
    FROM mcr.microsoft.com/oryx/python:3.7-20190712.5
    LABEL Name=altf1.be/plotly Version=1.19.0
    LABEL maintainer="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3455565b1f44585b40584d6b505b575f51466b474055535d5a53745558401952051a5651" rel="noreferrer noopener nofollow">[email protected]</a>"
    RUN mkdir /code
    WORKDIR /code
    ADD requirements.txt /code/
    # copy the code from the local drive to the docker
    ADD . /code/
    
    # non interactive front-end
    ARG DEBIAN_FRONTEND=noninteractive
    
    # update the software repository
    ENV SSH_PASSWD 'root:!astrongpassword!'
    
    RUN apt-get update && apt-get install -y \
        apt-utils \
        # enable SSH
        && apt-get install -y --no-install-recommends openssh-server \
        && echo "$SSH_PASSWD" | chpasswd
    
    RUN chmod u+x /code/init_container.sh
    
    # update the python packages and libraries
    
    RUN pip3 install --upgrade pip 
    RUN pip3 install --upgrade setuptools 
    RUN pip3 install --upgrade wheel
    RUN pip3 install -r requirements.txt
    
    # copy sshd_config file. See https://man.openbsd.org/sshd_config
    COPY sshd_config /etc/ssh/
    EXPOSE 8000 2222
    ENV PORT 8000
    ENV SSH_PORT 2222
    
    # install dependencies
    
    ENV ACCEPT_EULA=Y
    ENV APPENGINE_INSTANCE_CLASS=F2
    ENV apiUrl=https://api.beta.alt-f1.be
    ENV serverUrl=https://dunningcashflow-api.alt-f1.be
    
    ENV DOCKER_REGISTRY altf1be.azurecr.io
    
    ENTRYPOINT ["/code/init_container.sh"]
    

    /code/init_container.sh

    gunicorn --config=app/conf/gunicorn.conf.docker.staging.py app.webapp:server
    

    app/conf/gunicorn.conf.docker.staging.py

    # -*- coding: utf-8 -*-
    workers = 1
    # print("workers: {}".format(workers))
    bind = '0.0.0.0'
    timeout = 600
    log_level = "debug"
    reload = True
    print(
        f"workers={workers} bind={bind} timeout={timeout} --log-level={log_level} --reload={reload}"
    )
    

    容器设置

    Container settings - add command to run gunicorn

    应用程序设置

    Azure - application settings (update with WEBSITES_PORT)

    网络应用程序正在运行 - “服务不可用”

    Web App Error : the service unavailable

    Kudu -“服务不可用”

    Kudu - the service in unavailable

    Kudu - 端口 8000 上的 http ping(应用程序未运行)

    • 错误 - 站点 altf1be-plotly-docker 的容器 altf1be-plotly-docker_0_ee297002 已退出,站点启动失败

    • 错误 - 容器 altf1be-plotly-docker_0_ee297002 未响应端口 8000 上的 HTTP ping,站点启动失败。查看容器日志以进行调试。

    最佳答案

    我看到的是你使用了错误的环境变量,它应该是WEBSITES_PORT,你错过了WEBSITE后面的s。您可以添加它并尝试再次部署该镜像。

    而且我认为 Azure Web App 不会帮助您设置环境变量,就像您在 docker-compose 文件中使用选项 env_file 所做的那样。因此,我建议您通过命令 docker build 创建镜像,并通过 -e 设置环境变量在本地进行测试。当镜像运行良好时,您可以将其推送到 ACr 并使用 Web App 中的环境变量从 ACR 进行部署。

    或者您仍然可以使用 docker-compose 文件在 Web 应用程序中部署镜像,而不是使用 env_filebuild 以及 environment以及image(当图像采用 ACR 格式时)。

    关于Azure 容器生成错误 '503' 原因 'site unavailable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59373884/

    相关文章:

    .net - eventregister.exe 无法加载 Azure ServiceRuntime

    sql - 无法在 SQL Azure 中运行更新查询 *对象名称无效 'DataSync.provision_marker_dss' 。*

    postgresql - Crunchy Postgres 和 Hasura Graphql Engine 上的 Docker Compose - 数据库 URL 设置

    docker - 如何在Docker Compose中连接不同网络中的容器?

    php - docker-compose - 无法连接到 MySQL 数据库

    c# - 获取 Azure 区 block 链项目的不记名 token

    sql-server - 使用 SSMS 将 Azure 数据库备份到 .BAK 文件?

    docker - 运行 docker run :Error response from daemon 时出错

    java - 如何在不创建任何 mysql 服务器的情况下为本地主机/现有数据库运行 docker 容器?

    java - Docker Java 应用程序 - SSLHandshakeException/未找到可信证书