繁体   English   中英

在 Azure 应用服务上部署多容器应用

[英]Deploying a multi-container app on Azure App Services

几天来,我一直在努力部署一个 Azure 应用服务和两个极简主义的 Docker 容器。

我的第一张图片是基本的 PostgreSQL 图片,第二张图片是使用以下 Dockerfile 构建的:

FROM python:3.7
RUN pip install streamlit
COPY app.py /streamlit-docker/
WORKDIR /streamlit-docker/
CMD streamlit run app.py

app.py 在哪里:

import streamlit as st
st.write('Hello world')

我用于创建 Azure 应用程序服务的docker-compose.yml文件如下:

version: '3.3'

services:
    db:
        image: atestcr.azurecr.io/postgres:latest
        environment:
            POSTGRES_PASSWORD: postgres
    app:
        image: atestcr.azurecr.io/my_app:latest
        ports:
            - '8501:8501'

每当我尝试访问 webapp URL 时,我都会收到“应用程序错误”。但是,当我使用单个 docker 容器部署此应用程序时,使用此docker-compose.yml

version: '3.3'

services:
    app:
        image: atestcr.azurecr.io/my_app:latest
        ports:
            - '8501:8501'

一切正常。

这是一个GitHub repo来重现这个错误。

这些是 Azure 日志:

2021-08-09T17:29:34.382Z INFO  - Starting multi-container app..
2021-08-09T17:29:35.089Z INFO  - Pulling image: atestcr.azurecr.io/postgres:latest
2021-08-09T17:29:35.313Z INFO  - latest Pulling from postgres
2021-08-09T17:29:35.315Z INFO  -  Digest: sha256:b6df1345afa5990ea32866e5c331eefbf2e30a05f2a715c3a9691a6cb18fa253
2021-08-09T17:29:35.317Z INFO  -  Status: Image is up to date for atestcr.azurecr.io/postgres:latest
2021-08-09T17:29:35.319Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-08-09T17:29:35.335Z INFO  - Starting container for site
2021-08-09T17:29:35.335Z INFO  - docker run -d -p 8477:5432 --name testapp32_db_0_6662435d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=testapp32 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=testapp32.azurewebsites.net -e WEBSITE_INSTANCE_ID=42c09ff46e6c54cb467d28e88f2ab5b1e8971ee4daf2e883f44401bde67fe89f -e HTTP_LOGGING_ENABLED=1 atestcr.azurecr.io/postgres:latest  

2021-08-09T17:29:35.781Z INFO  - Pulling image: atestcr.azurecr.io/my_app:latest
2021-08-09T17:29:35.984Z INFO  - latest Pulling from my_app
2021-08-09T17:29:35.987Z INFO  -  Digest: sha256:659937a52a6223b938b3d429901ab8648497870bf8068b5dcc05816050db5eaf
2021-08-09T17:29:35.988Z INFO  -  Status: Image is up to date for atestcr.azurecr.io/my_app:latest
2021-08-09T17:29:35.993Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-08-09T17:29:36.014Z INFO  - Starting container for site
2021-08-09T17:29:36.014Z INFO  - docker run -d -p 0:8501 --name testapp32_app_0_6662435d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=testapp32 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=testapp32.azurewebsites.net -e WEBSITE_INSTANCE_ID=42c09ff46e6c54cb467d28e88f2ab5b1e8971ee4daf2e883f44401bde67fe89f -e HTTP_LOGGING_ENABLED=1 atestcr.azurecr.io/my_app:latest  

2021-08-09T17:33:26.741Z ERROR - multi-container unit was not started successfully
2021-08-09T17:33:26.846Z INFO  - Container logs from testapp32_db_0_6662435d = 2021-08-09T17:29:40.459721366Z The files belonging to this database system will be owned by user "postgres".
2021-08-09T17:29:40.491740899Z This user must also own the server process.
2021-08-09T17:29:40.493019808Z 
2021-08-09T17:29:40.497263739Z The database cluster will be initialized with locale "en_US.utf8".
2021-08-09T17:29:40.502456876Z The default database encoding has accordingly been set to "UTF8".
2021-08-09T17:29:40.503203182Z The default text search configuration will be set to "english".
2021-08-09T17:29:40.503218482Z 
2021-08-09T17:29:40.503223282Z Data page checksums are disabled.
2021-08-09T17:29:40.506809008Z 
2021-08-09T17:29:40.521275113Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
2021-08-09T17:29:40.523912632Z creating subdirectories ... ok
2021-08-09T17:29:40.525237242Z selecting dynamic shared memory implementation ... posix
2021-08-09T17:29:40.642905697Z selecting default max_connections ... 100
2021-08-09T17:29:40.733900958Z selecting default shared_buffers ... 128MB
2021-08-09T17:29:41.039050775Z selecting default time zone ... Etc/UTC
2021-08-09T17:29:41.047757638Z creating configuration files ... ok
2021-08-09T17:29:44.416903507Z running bootstrap script ... ok
2021-08-09T17:29:50.023628737Z performing post-bootstrap initialization ... ok
2021-08-09T17:30:04.217544961Z syncing data to disk ... ok
2021-08-09T17:30:04.218321267Z 
2021-08-09T17:30:04.219189873Z initdb: warning: enabling "trust" authentication for local connections
2021-08-09T17:30:04.219206473Z You can change this by editing pg_hba.conf or using the option -A, or
2021-08-09T17:30:04.219223973Z --auth-local and --auth-host, the next time you run initdb.
2021-08-09T17:30:04.219491175Z 
2021-08-09T17:30:04.219513275Z Success. You can now start the database server using:
2021-08-09T17:30:04.219519575Z 
2021-08-09T17:30:04.219523675Z     pg_ctl -D /var/lib/postgresql/data -l logfile start
2021-08-09T17:30:04.219527775Z 
2021-08-09T17:30:08.340584036Z waiting for server to start.......2021-08-09 17:30:08.340 UTC [44] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-08-09T17:30:08.478247580Z 2021-08-09 17:30:08.410 UTC [44] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-08-09T17:30:08.680599067Z 2021-08-09 17:30:08.680 UTC [45] LOG:  database system was shut down at 2021-08-09 17:29:49 UTC
2021-08-09T17:30:08.753589768Z 2021-08-09 17:30:08.753 UTC [44] LOG:  database system is ready to accept connections
2021-08-09T17:30:08.755965684Z  done
2021-08-09T17:30:08.760382514Z server started
2021-08-09T17:30:09.790821978Z 
2021-08-09T17:30:09.799723839Z /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2021-08-09T17:30:09.802079455Z 
2021-08-09T17:30:09.840304817Z 2021-08-09 17:30:09.834 UTC [44] LOG:  received fast shutdown request
2021-08-09T17:30:09.862102366Z waiting for server to shut down....2021-08-09 17:30:09.861 UTC [44] LOG:  aborting any active transactions
2021-08-09T17:30:09.950488072Z 2021-08-09 17:30:09.950 UTC [44] LOG:  background worker "logical replication launcher" (PID 51) exited with exit code 1
2021-08-09T17:30:09.954360498Z 2021-08-09 17:30:09.950 UTC [46] LOG:  shutting down
2021-08-09T17:30:13.063848848Z ...2021-08-09 17:30:13.063 UTC [44] LOG:  database system is shut down
2021-08-09T17:30:13.138558463Z  done
2021-08-09T17:30:13.140082774Z server stopped
2021-08-09T17:30:13.144102302Z 
2021-08-09T17:30:13.162430928Z PostgreSQL init process complete; ready for start up.
2021-08-09T17:30:13.165654351Z 
2021-08-09T17:30:14.083504086Z 2021-08-09 17:30:13.992 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-08-09T17:30:14.084760295Z 2021-08-09 17:30:14.011 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-08-09T17:30:14.084774095Z 2021-08-09 17:30:14.015 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-08-09T17:30:14.084779495Z 2021-08-09 17:30:14.082 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-08-09T17:30:14.156076187Z 2021-08-09 17:30:14.132 UTC [63] LOG:  database system was shut down at 2021-08-09 17:30:12 UTC
2021-08-09T17:30:14.198749982Z 2021-08-09 17:30:14.176 UTC [1] LOG:  database system is ready to accept connections
2021-08-09T17:30:15.006882460Z 2021-08-09 17:30:14.998 UTC [70] LOG:  invalid length of startup packet
2021-08-09T17:30:16.112919592Z 2021-08-09 17:30:16.112 UTC [71] LOG:  invalid length of startup packet
2021-08-09T17:30:17.178350344Z 2021-08-09 17:30:17.174 UTC [72] LOG:  invalid length of startup packet
...
2021-08-09T17:33:25.735293291Z 2021-08-09 17:33:25.735 UTC [260] LOG:  invalid length of startup packet

2021-08-09T17:33:29.142Z INFO  - Container logs from testapp32_app_0_6662435d = 2021-08-09T17:30:24.010212694Z 
2021-08-09T17:30:24.011085300Z   You can now view your Streamlit app in your browser.
2021-08-09T17:30:24.011101800Z 
2021-08-09T17:30:24.012092107Z   Network URL: http://172.16.232.3:8501
2021-08-09T17:30:24.012855612Z   External URL: http://20.40.148.207:8501
2021-08-09T17:30:24.013407416Z 

2021-08-09T17:33:36.002Z INFO  - Stopping site testapp32 because it failed during startup.

值得注意的是,您的共享示例不起作用,因为您的docker-compose.yml使用的是您自己的私有容器注册表。

然而,在边缘修补我已经设法让你的虚拟示例处理对以下文件的更改:

您的应用 dockerfile:

FROM python:3.7
RUN pip install streamlit
COPY app.py /streamlit-docker/
WORKDIR /streamlit-docker/
EXPOSE 80
CMD streamlit run app.py --server.port 80

并调整您的docker-compose.yml

version: '3.3'

services:
    db:
        image: postgis/postgis:13-master
        environment:
            - POSTGRES_DB=counterfactualcovid
            - POSTGRES_USER=django
            - POSTGRES_PASSWORD=django
    app:
        image: testazurecontainerregistryajc.azurecr.io/mcmegaapp:latest
        ports:
            - '80:80'

忽略我使用了一个通用的 postgres docker 图像和我自己的图像私有容器注册表这一事实,你会看到关键的变化是:

  • 在 Dockerfile 暴露端口 80,并将--server.port 80添加到 streamlit CMD 调用
  • 在 docker-compose.yml 中将端口转发设置为80:80

我/认为/您的问题是由多容器 web 应用程序功能的预览限制引起的,因此将所有内容设置为通过端口 80 工作似乎可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM