clank
clank

Reputation: 83

Deploying a multi-container app on Azure App Services

I have been struggling for some days now to deploy an Azure App Service with two minimalist Docker containers.

My first image is a basic PostgreSQL image and my second image is built with the following Dockerfile:

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

and where app.py is:

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

The docker-compose.yml file I use for creating my Azure App service is the following:

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'

I get an 'Application Error' whenever I try to access the webapp URL. However, when I deploy this app with a single docker container, using this docker-compose.yml:

version: '3.3'

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

everything works fine.

Here is a GitHub repo to recreate the bug.

These are the Azure logs:

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.

Upvotes: 0

Views: 3386

Answers (1)

Sparrow0hawk
Sparrow0hawk

Reputation: 577

It's worth noting your shared example doesn't work because your docker-compose.yml is using your own private container registries.

However, tinkering around the edges I have managed to get your dummy example working with changes to the following files:

Your app 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

And adjusting your 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'

Ignore the fact i've used a generic postgres docker image and my own private container registry for the images and you'll see the key changes are:

  • in the Dockerfile exposing port 80, and adding --server.port 80 to the streamlit CMD call
  • in the docker-compose.yml setting the port forwarding to 80:80

I /think/ your issues arise from the preview limitations for the multi-container web apps feature, so setting everything to work via port 80 appears to resolve this.

Upvotes: 1

Related Questions