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

Azure Container generates error '503' reason 'site unavailable'

问题

我在本地机器上构建了一个 docker 映像 运行ning windows 10

  1. 运行宁docker-compose builddocker-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 图像上传到私有 Azure 容器注册表

  4. 我根据 docker 图像部署网络应用 Azure Portal > Container registry > Repositories > altf1be.plotly.docker-compose > v2019-12-17 > context-menu > deploy to web app

  1. 我 运行 网络应用程序,我得到 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

Docker 文件

# 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://docs.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="abo+plotly_docker_staging@alt-f1.be"
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}"
)

容器设置

应用程序设置

网络应用程序 运行宁 - 'the service is unavailable'

捻角羚 - 'the service is unavailable'

Kudu - 在端口 8000 上进行 http ping(该应用未 运行ning)

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

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

或者您仍然可以使用 docker-compose 文件在 Web App 中部署您的图像,而不是 env_filebuild 以及 environmentimage 当图像在 ACR 中时。