部署后 Azure 容器实例未通过 url 显示任何内容

Azure Container Instance not showing anything via url after deployment

我正在尝试在 Azure 上部署一个 docker 图像。我能够成功创建 docker 图像,也成功部署。但是我在指定为容器创建部署的 URL 上看不到任何内容。我的应用程序是一个 python flask 应用程序,它也使用破折号。

我关注了this azure tutorial from documentation。示例应用程序有效。但我的应用程序没有。我不知道如何调试这个或哪里出错了。

Dockerfile

FROM ubuntu:18.04

COPY . /app

WORKDIR /app

RUN apt update && \
    apt install -y make curl gcc g++ gfortran git patch wget unixodbc-dev vim-tiny build-essential \
    libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \
    libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev && \
    apt install -y python3 python3-dev python3-pip python3-venv && \
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt update && \
    ACCEPT_EULA=Y apt-get -y install msodbcsql17 && \
    python3 -m venv spo_venv && \
    . spo_venv/bin/activate && \
    pip3 install --upgrade pip && \
    pip3 install wheel && \
    pip3 install -r requirements.txt && \
    cd / && \
    wget http://download.redis.io/releases/redis-5.0.5.tar.gz && \
    tar xzf redis-5.0.5.tar.gz && \
    cd redis-5.0.5 && \
    make && \
#    make test && \
    cd / && \
    rm redis-5.0.5.tar.gz && \
    cd / && \
    wget https://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.13.tgz && \
    tar xvzf Ipopt-3.12.13.tgz && \
    cd Ipopt-3.12.13/ThirdParty/Blas/ && \
    ./get.Blas && \
    cd ../Lapack && \
    ./get.Lapack && \
    cd ../Mumps && \
    ./get.Mumps && \
    cd ../Metis && \
    ./get.Metis && \
    cd ../../ && \
    mkdir build && \
    cd build && \
    ../configure && \
    make -j 4 && \
    make install && \
    cd / && \
    rm Ipopt-3.12.13.tgz && \
    echo "export PATH=\"$PATH:/redis-5.0.5/src/\"" >> ~/.bashrc && \
   . ~/.bashrc

CMD ["./commands.sh"]

commands.sh

#!/bin/sh
. spo_venv/bin/activate
nohup redis-server > redislogs.log 2>&1 &
nohup celery worker -A task.celery -l info -P eventlet > celerylogs.log 2>&1 &
python app.py

Azure 命令

sudo az acr login --name mynameregistry

sudo az acr show --name mynameregistry--query loginServer --output table

sudo docker tag spo_third_trial:v1 mynameregistry.azurecr.io/spo_third_trial:v1

sudo docker push mynameregistry.azurecr.io/spo_third_trial:v1

sudo az acr repository list --name mynameregistry--output table

sudo az acr repository show-tags --name mynameregistry--repository spo_third_trial --output table

sudo az acr show --name mynameregistry--query loginServer

sudo az container create --resource-group myResourceGroup --name spo-third-trial --image mynameregistry.azurecr.io/spo_third_trial:v1 --cpu 1 --memory 1 --registry-login-server mynameregistry.azurecr.io --registry-username mynameregistry --registry-password randomPassword --dns-name-label spo-third-trial --ports 80 8050

但是当我去 http://spo-third-trial.eastus.azurecontainer.io 我明白了。

This site can’t be reached spo-third-trial.eastus.azurecontainer.io took too long to respond. Search Google for spo third trial eastus azure container io ERR_CONNECTION_TIMED_OUT

当我使用此命令访问日志时 sudo az container logs --resource-group myResourceGroup --name spo-third-trial 我得到了这个

Running on http://127.0.0.1:8050/
Debugger PIN: 950-132-306
 * Serving Flask app "server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
Running on http://127.0.0.1:8050/
Debugger PIN: 871-957-278

我的卷曲输出

 curl -v http://spo-third-trial.eastus.azurecontainer.io

* Rebuilt URL to: http://spo-third-trial.eastus.azurecontainer.io/
*   Trying <ip-address>...
* TCP_NODELAY set
* connect to <ip-address> port 80 failed: Connection timed out
* Failed to connect to spo-third-trial.eastus.azurecontainer.io port 80: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to spo-third-trial.eastus.azurecontainer.io port 80: Connection timed out

我不明白我在创建 docker 或 azure 时是否做错了,或两者都有。我将不胜感激。

注意:我正在虚拟 PC - AWS 客户端上工作,以访问客户端内的 azure。

正如所讨论的,您的问题有几点:

  • 我认为你的意思是将内部端口 8050 映射到外部端口 80。但这在 Azure 容器实例中目前(2019 年 8 月)是不可能的。 Uservoice for this. --ports 80 8050 means that you expose both ports 上有一个打开的项目,不是你将一个映射到另一个。
  • 正如我们发现的那样,实际问题是 python flask 应用仅在 127.0.0.1 上监听,而不是 0.0.0.0。所以它不接受来自外部的请求。