Azure容器生成错误“ 503”,原因“站点不可用”

时间:2019-12-17 12:02:52

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

问题

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

  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. 可以正确运行应用
  4. 我将docker映像上传到私有Azure容器注册表中

  5. 我基于docker镜像Azure Portal > Container registry > Repositories > altf1be.plotly.docker-compose > v2019-12-17 > context-menu > deploy to web app

  6. 部署Web应用

Azure - Deploy the web app from a docker image

  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

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://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}"
)

容器设置

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,站点启动失败。请参阅容器日志以进行调试。

1 个答案:

答案 0 :(得分:1)

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

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

或者,您仍然可以使用docker-compose文件在Web App中部署映像,而不是在映像时使用env_filebuild的{​​{1}}和environment在ACR中。