skip to Main Content

Update 30.01.2024: It works now. See my answer below

The following was the starting point

I try to host a Web App with Azure via Docker Compose.

When I run sudo docker-compose up --build on my computer, everything works fine.

But when I try to run it on Azure I get the following error in the log stream:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/><title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title><style type="text/css"><!--body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}fieldset{padding:0 15px 10px 15px;}h1{font-size:2.4em;margin:0;color:#FFF;}h2{font-size:1.7em;margin:0;color:#CC0000;}h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;background-color:#555555;}#content{margin:0 0 0 2%;position:relative;}.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}--></style></head><body><div id="header"><h1>Server Error</h1></div><div id="content"><div class="content-container"><fieldset><h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2><h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3></fieldset></div></div></body></html>

My docker-compose.yml which I use to build the containers locally:

# docker compose file version
# It is a docker intrinsic number.
version: '3.8'

services:

  web:
    build:
      context: .
      dockerfile: Dockerfile
    image:
         # registry_path:tag (tag defines name in registry)  
         fastapiuploadfiles.azurecr.io/uploadfiles:web_app
    ports:
        # Host Port:Container Port
      - 80:8080
    command: uvicorn app.upload_file:app --host 0.0.0.0
    volumes:
      - .:/api_code
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - redis

  
  worker:
    build:
      context: .
      dockerfile: Dockerfile   
    image: fastapiuploadfiles.azurecr.io/uploadfiles:worker_app
    command: celery --app=celery_task_app.worker.celery_app worker --loglevel=info --logfile=logs/celery.log
    volumes:
      - .:/api_code
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - web
      - redis

  
  redis:
    image: redis:7


  dashboard:
    build: 
      context: .
      dockerfile: Dockerfile
    image: fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app
    command: celery --broker=redis://redis:6379/0 flower --port=8080
    ports:
      - 8080:8080
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - web
      - redis
      - worker

My docker file:

# Start from the official Python base image.

FROM python:3.9


# Set the current working directory to "." (current directory)
# If you want to change set WORKDIR ./selected_dir
# This is where we'll put the requirements.txt file and the app directory.
WORKDIR /api_code

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip

# Copy the file with the requirements to the ./api_code directory.
# Copy only the file with the requirements first, not the rest of the code.
# As this file doesn't change often, Docker will detect it and use the cache for this step,
# enabling the cache for the next step too.
COPY ./requirements.txt /api_code/requirements.txt


# Install the package dependencies in the requirements file.
RUN pip install --no-cache-dir --upgrade -r /api_code/requirements.txt

RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends ffmpeg


# torch
#RUN pip install torch==1.13.0+cpu torchvision==0.14.0+cpu torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cpu
RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu


# whisper X
RUN pip install git+https://github.com/m-bain/whisperx.git


# Copy the ./app directory inside the ./api_code/app directory.
# As this has all the code which is what changes most
# frequently the Docker cache won't be used for this or
# any following steps easily.
# So, it's important to put this near the end of the
# Dockerfile, to optimize the container image build times.

COPY ./app /api_code/app

COPY ./logs /api_code/logs

COPY ./celery_task_app /api_code/celery_task_app

EXPOSE 80

Here are my steps regarding Azure:

  1. Upload images with bash script to the Azure Container Registry:

    #!/bin/sh
    
    cat azure_pwd | docker login fastapiuploadfiles.azurecr.io -u fastapiuploadfiles --password-stdin
    
    cd dir_to_push
    
    docker-compose build --pull
    
    echo -ne "ndocker ps:n"
    
    docker ps
    
    echo -ne "ndocker images:n"
    
    docker images
    
    echo -ne "n Start push:n"
    
    docker-compose push
    

(2) Create Azure Web App via the website. At this point, I am unsure what the docker-compose.yml file that Azure expects should look like. I used the yml above and I used the yml above without the build parameter. But is that right? Both gave me the same error I mentioned above. Because of this link I also used the following yml for Azure:

# docker compose file version
# It is a docker intrinsic number.
version: '3.8'

services:

  web:
    image:
         # registry_path:tag (tag defines name in registry)  
         fastapiuploadfiles.azurecr.io/uploadfiles:web_app
    ports:
        # Host Port:Container Port
      - 80:8080
    command: uvicorn app.upload_file:app --host 0.0.0.0
    volumes:
      - .:/api_code
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    

  
  worker:
    image: fastapiuploadfiles.azurecr.io/uploadfiles:worker_app
    command: celery --app=celery_task_app.worker.celery_app worker --loglevel=info --logfile=logs/celery.log
    volumes:
      - .:/api_code
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    

  
  redis:
    image: redis:7


  dashboard:
    image: fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app
    command: celery --broker=redis://redis:6379/0 flower --port=8080
    ports:
      - 8080:8080
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0

I tried to find a solution but all the templates which tell me how the yml file has to look like for Azure have failed.

Update

Azure says me:
(A)

Some container port settings were found from logs
Exposed port by container
8080
Listening port by container
Unknown

(B) Log file:

Ok
2024-01-16T17:35:08.023

INFO  - fe63dfc5d102 Extracting 294MB / 297MB
  Ok

2024-01-16T17:35:10.699
INFO  - fe63dfc5d102 Extracting 297MB / 297MB
  Ok

2024-01-16T17:35:10.851
INFO  - fe63dfc5d102 Pull complete
  Ok

2024-01-16T17:35:10.852
INFO  - 4e06fb156a35 Extracting 32KB / 141KB
  Ok

2024-01-16T17:35:10.892
INFO  - 4e06fb156a35 Extracting 141KB / 141KB
  Ok

2024-01-16T17:35:10.902
INFO  - 4e06fb156a35 Pull complete
  Ok

2024-01-16T17:35:10.904
INFO  - 2bbbb0546bb4 Extracting 13KB / 13KB
  Ok

2024-01-16T17:35:10.947
INFO  - 2bbbb0546bb4 Extracting 13KB / 13KB
  Ok

2024-01-16T17:35:10.953
INFO  - 2bbbb0546bb4 Pull complete
  Ok

2024-01-16T17:35:10.955
INFO  - ac86d66f05e7 Extracting 3KB / 3KB
  Ok

2024-01-16T17:35:10.959
INFO  - ac86d66f05e7 Extracting 3KB / 3KB
  Ok

2024-01-16T17:35:11.002
INFO  - ac86d66f05e7 Pull complete
  Ok

2024-01-16T17:35:11.088
INFO  -  Digest: sha256:b57a692c3859e204572a47aedb4602e2a4f6f2c85a8cbdc0e11cb1fa97579196
  Ok

2024-01-16T17:35:11.09
INFO  -  Status: Downloaded newer image for fastapiuploadfiles.azurecr.io/uploadfiles:web_app
  Ok

2024-01-16T17:35:11.102
INFO  - Pull Image successful, Time taken: 202 Seconds
  Ok

2024-01-16T17:35:11.111
INFO  - Starting container for site

  Warning
2024-01-16T17:35:11.111

INFO  - docker run -d -p 8603:8080 --name api-celery_web_0_306850dd -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=api-celery -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=api-celery.azurewebsites.net -e WEBSITE_INSTANCE_ID=7fad53901ff1c3f65572da614477223d2fcd732e602f4adf52edc818614e0589 -e HTTP_LOGGING_ENABLED=1 fastapiuploadfiles.azurecr.io/uploadfiles:web_app uvicorn app.upload_file:app --host 0.0.0.0
  Ok

2024-01-16T17:35:13.182
INFO  - Pulling image: fastapiuploadfiles.azurecr.io/uploadfiles:worker_app
  Ok

2024-01-16T17:35:13.432
INFO  - worker_app Pulling from uploadfiles
  Ok

2024-01-16T17:35:13.46
INFO  -  Digest: sha256:b57a692c3859e204572a47aedb4602e2a4f6f2c85a8cbdc0e11cb1fa97579196
  Ok

2024-01-16T17:35:13.461
INFO  -  Status: Downloaded newer image for fastapiuploadfiles.azurecr.io/uploadfiles:worker_app
  Ok

2024-01-16T17:35:13.473
INFO  - Pull Image successful, Time taken: 0 Seconds
  Ok

2024-01-16T17:35:13.481
INFO  - Starting container for site
  Ok

2024-01-16T17:35:13.481
INFO  - docker run -d  --name api-celery_worker_0_306850dd -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=api-celery -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=api-celery.azurewebsites.net -e WEBSITE_INSTANCE_ID=7fad53901ff1c3f65572da614477223d2fcd732e602f4adf52edc818614e0589 -e HTTP_LOGGING_ENABLED=1 fastapiuploadfiles.azurecr.io/uploadfiles:worker_app celery --app=celery_task_app.worker.celery_app worker --loglevel=info --logfile=logs/celery.log
  Ok

2024-01-16T17:35:13.503
INFO  - Pulling image: redis:7
  Warning
2024-01-16T17:35:14.112
ERROR - DockerApiException: Docker API responded with status code=InternalServerError, response={"message":"Head "https://registry-1.docker.io/v2/library/redis/manifests/7": unauthorized: incorrect username or password"}
  Ok

2024-01-16T17:35:14.112
  Ok

2024-01-16T17:35:14.112
ERROR - Pulling docker image redis:7 failed:
  Ok

2024-01-16T17:35:15.454
INFO  - 7 Pulling from library/redis
  Ok

2024-01-16T17:35:15.856
INFO  - 2f44b7a888fa Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - c55535369ffc Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - 3622841bf0aa Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - 91a62ca7377a Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - fdd219d1f4ab Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - fdf07fe2fb4c Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - 4f4fb700ef54 Pulling fs layer
  Ok

2024-01-16T17:35:15.856
INFO  - fba604e70bfe Pulling fs layer
  Ok

2024-01-16T17:35:16.189
INFO  - 3622841bf0aa Downloading 721B / 875B
  Ok

2024-01-16T17:35:16.189
INFO  - 3622841bf0aa Downloading 875B / 875B
  Ok

2024-01-16T17:35:16.189
INFO  - 3622841bf0aa Verifying Checksum
  Ok

2024-01-16T17:35:16.189
INFO  - 3622841bf0aa Download complete
  Ok

2024-01-16T17:35:16.191
INFO  - fdf07fe2fb4c Downloading 96B / 96B
  Ok

2024-01-16T17:35:16.191
INFO  - fdf07fe2fb4c Verifying Checksum
  Ok

2024-01-16T17:35:16.191
INFO  - fdf07fe2fb4c Download complete
  Ok

2024-01-16T17:35:16.197
INFO  - c55535369ffc Downloading 1KB / 1KB
  Ok

2024-01-16T17:35:16.197
INFO  - c55535369ffc Verifying Checksum
  Ok

2024-01-16T17:35:16.198
INFO  - c55535369ffc Download complete
  Ok

2024-01-16T17:35:16.198
INFO  - fba604e70bfe Downloading 572B / 572B
  Ok

2024-01-16T17:35:16.198
INFO  - fba604e70bfe Verifying Checksum
  Ok

2024-01-16T17:35:16.198
INFO  - fba604e70bfe Download complete
  Ok

2024-01-16T17:35:16.205
INFO  - 91a62ca7377a Verifying Checksum
  Ok

2024-01-16T17:35:16.206
INFO  - 91a62ca7377a Download complete
  Ok

2024-01-16T17:35:16.208
INFO  - 4f4fb700ef54 Downloading 32B / 32B
  Ok

2024-01-16T17:35:16.209
INFO  - 4f4fb700ef54 Verifying Checksum
  Ok

2024-01-16T17:35:16.209
INFO  - 4f4fb700ef54 Download complete
  Ok

2024-01-16T17:35:16.359
INFO  - fdd219d1f4ab Verifying Checksum
  Ok

2024-01-16T17:35:16.36
INFO  - fdd219d1f4ab Download complete
  Ok

2024-01-16T17:35:16.483
INFO  - 2f44b7a888fa Verifying Checksum
  Ok

2024-01-16T17:35:16.483
INFO  - 2f44b7a888fa Download complete
  Ok

2024-01-16T17:35:16.651
INFO  - 2f44b7a888fa Extracting 3MB / 27MB
  Ok

2024-01-16T17:35:16.979
INFO  - 2f44b7a888fa Extracting 11MB / 27MB
  Ok

2024-01-16T17:35:17.081
INFO  - 2f44b7a888fa Extracting 15MB / 27MB
  Ok

2024-01-16T17:35:17.286
INFO  - 2f44b7a888fa Extracting 21MB / 27MB
  Ok

2024-01-16T17:35:17.514
INFO  - 2f44b7a888fa Extracting 26MB / 27MB
  Ok

2024-01-16T17:35:17.746
INFO  - 2f44b7a888fa Extracting 27MB / 27MB
  Ok

2024-01-16T17:35:17.788
INFO  - 2f44b7a888fa Pull complete
  Ok

2024-01-16T17:35:17.79
INFO  - c55535369ffc Extracting 1KB / 1KB
  Ok

2024-01-16T17:35:17.793
INFO  - c55535369ffc Extracting 1KB / 1KB
  Ok

2024-01-16T17:35:17.84
INFO  - c55535369ffc Pull complete
  Ok

2024-01-16T17:35:17.842
INFO  - 3622841bf0aa Extracting 875B / 875B
  Ok

2024-01-16T17:35:17.845
INFO  - 3622841bf0aa Extracting 875B / 875B
  Ok

2024-01-16T17:35:17.888
INFO  - 3622841bf0aa Pull complete
  Ok

2024-01-16T17:35:17.89
INFO  - 91a62ca7377a Extracting 32KB / 1MB
  Ok

2024-01-16T17:35:17.979
INFO  - 91a62ca7377a Extracting 1MB / 1MB
  Ok

2024-01-16T17:35:17.981
INFO  - 91a62ca7377a Extracting 1MB / 1MB
  Ok

2024-01-16T17:35:17.988
INFO  - 91a62ca7377a Pull complete
  Ok

2024-01-16T17:35:18.159
INFO  - fdd219d1f4ab Extracting 1MB / 19MB
  Ok

2024-01-16T17:35:18.464
INFO  - fdd219d1f4ab Extracting 8MB / 19MB
  Ok

2024-01-16T17:35:18.969
INFO  - fdd219d1f4ab Extracting 19MB / 19MB
  Ok

2024-01-16T17:35:18.986
INFO  - fdd219d1f4ab Pull complete
  Ok

2024-01-16T17:35:18.988
INFO  - fdf07fe2fb4c Extracting 96B / 96B
  Ok

2024-01-16T17:35:18.991
INFO  - fdf07fe2fb4c Extracting 96B / 96B
  Ok

2024-01-16T17:35:19.036
INFO  - fdf07fe2fb4c Pull complete
  Ok

2024-01-16T17:35:19.038
INFO  - 4f4fb700ef54 Extracting 32B / 32B
  Ok

2024-01-16T17:35:19.04
INFO  - 4f4fb700ef54 Extracting 32B / 32B
  Ok

2024-01-16T17:35:19.083
INFO  - 4f4fb700ef54 Pull complete
  Ok

2024-01-16T17:35:19.085
INFO  - fba604e70bfe Extracting 572B / 572B
  Ok

2024-01-16T17:35:19.094
INFO  - fba604e70bfe Extracting 572B / 572B
  Ok

2024-01-16T17:35:19.141
INFO  - fba604e70bfe Pull complete
  Ok

2024-01-16T17:35:19.173
INFO  -  Digest: sha256:b5ddcd52d425a8e354696c022f392fe45fca928f68d6289e6bb4a709c3a74668
  Ok

2024-01-16T17:35:19.174
INFO  -  Status: Downloaded newer image for redis:7
  Ok

2024-01-16T17:35:19.185
INFO  - Pull Image successful, Time taken: 5 Seconds
  Ok

2024-01-16T17:35:19.197
INFO  - Starting container for site
  Ok

2024-01-16T17:35:19.197
INFO  - docker run -d  --name api-celery_redis_0_306850dd -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=api-celery -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=api-celery.azurewebsites.net -e WEBSITE_INSTANCE_ID=7fad53901ff1c3f65572da614477223d2fcd732e602f4adf52edc818614e0589 -e HTTP_LOGGING_ENABLED=1 redis:7 
  Ok

2024-01-16T17:35:20.429
INFO  - Pulling image: fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app
  Ok

2024-01-16T17:35:20.641
INFO  - dashboard_app Pulling from uploadfiles
  Ok

2024-01-16T17:35:20.651
INFO  -  Digest: sha256:b57a692c3859e204572a47aedb4602e2a4f6f2c85a8cbdc0e11cb1fa97579196
  Ok

2024-01-16T17:35:20.652
INFO  -  Status: Downloaded newer image for fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app
  Ok

2024-01-16T17:35:20.667
INFO  - Pull Image successful, Time taken: 0 Seconds
  Ok

2024-01-16T17:35:21.101
INFO  - Starting container for site
  Ok

2024-01-16T17:35:21.101
INFO  - docker run -d  --name api-celery_dashboard_0_306850dd -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=api-celery -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=api-celery.azurewebsites.net -e WEBSITE_INSTANCE_ID=7fad53901ff1c3f65572da614477223d2fcd732e602f4adf52edc818614e0589 -e HTTP_LOGGING_ENABLED=1 fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app celery --broker=redis://redis:6379/0 flower --port=8080

Update 17.01.2024

I tagged the redis container with docker tag redis:7 fastapiuploadfiles.azurecr.io/uploadfiles:redis_app. So I was able to push all containers – including redis. When I start the containers with the yml file of Suresh Chikkam and try to open the link to the frontend of my app (web_app tag) I get the following log stream output:

Error occurred, type: error, text: Response Content-Length mismatch: too many bytes written (94517 of 66268)., stackTrace: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.VerifyAndUpdateWrite(Int32 count)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WritePipeAsync(ReadOnlyMemory1 data, CancellationToken cancellationToken)at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(ReadOnlyMemory1 source, CancellationToken cancellationToken)at Microsoft.AspNetCore.Http.StreamCopyOperationInternal.CopyToAsync(Stream source, Stream destination, Nullable`1 count, Int32 bufferSize, CancellationToken cancel)at Microsoft.AspNetCore.Internal.FileResultHelper.WriteFileAsync(HttpContext context, Stream fileStream, RangeItemHeaderValue range, Int64 rangeLength)at Microsoft.AspNetCore.Mvc.Infrastructure.FileResultExecutorBase.WriteFileAsync(HttpContext context, Stream fileStream, RangeItemHeaderValue range, Int64 rangeLength)at Microsoft.AspNetCore.Mvc.Infrastructure.FileStreamResultExecutor.ExecuteAsync(ActionContext context, FileStreamResult result)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)at Kudu.Services.Web.Tracing.TraceMiddleware.Invoke(HttpContext context) in /tmp/KuduLite/Kudu.Services.Web/Tracing/TraceMiddleware.cs:line 95

After start up of the containers:

docker run -d –name api-celery_dashboard_0_4022f740 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=api-celery -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=api-celery.azurewebsites.net -e WEBSITE_INSTANCE_ID=7fad53901ff1c3f65572da614477223d2fcd732e602f4adf52edc818614e0589 -e HTTP_LOGGING_ENABLED=1 fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app celery –broker=redis://redis:6379/0 flower –port=8080/home/LogFiles/2024_01_17_ln0xsdlwk000019_redis_docker.log (https://api-celery.scm.azurewebsites.net/api/vfs/LogFiles/2024_01_17_ln0xsdlwk000019_redis_docker.log)/home/LogFiles/2024_01_17_ln0xsdlwk000019_web_docker.log (https://api-celery.scm.azurewebsites.net/api/vfs/LogFiles/2024_01_17_ln0xsdlwk000019_web_docker.log)/home/LogFiles/2024_01_17_ln0xsdlwk000019_worker_docker.log (https://api-celery.scm.azurewebsites.net/api/vfs/LogFiles/2024_01_17_ln0xsdlwk000019_worker_docker.log)Ending Log Tail of existing logs —Starting Live Log Stream —

30.01.2024: It works now. See my answer below

2

Answers


  1. Chosen as BEST ANSWER

    It works now.

    (1) docker-compose.yml to build containers:

    version: '3.8'
    
    services:
    
      web:
        build: 
          context: .
          dockerfile: Dockerfile
        image: # registry_path:tag (tag defines name in registry)  
            fastapiuploadfiles.azurecr.io/uploadfiles:web_app_2.4
        ports:
            # Host Port:Container Port
          - 80:8000
        command: uvicorn app.upload_file:app --host 0.0.0.0
        volumes:
          - type: bind
            source: /home/tw/wav_data_host
            target: /api_code/app/wav_data
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - redis
    
      
      worker:
        build:
          context: .
          dockerfile: Dockerfile
        image: fastapiuploadfiles.azurecr.io/uploadfiles:worker_app_2.4
        command: > 
                 celery
                 --app=celery_task_app.worker.celery_app worker
                 --loglevel=info
                 --logfile=logs/celery.log
        volumes:
          - type: bind
            source: /home/tw/wav_data_host
            target: /api_code/app/wav_data
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
          - redis
    
      
      redis:
        image: redis:7
    
    
      dashboard:
        build: 
          context: .
          dockerfile: Dockerfile
        image: fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app_2.4
        command: celery --broker=redis://redis:6379/0 flower --port=5555
        ports:
          - 8080:5555
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
          - redis
          - worker
    

    (2) Dockerfile:

    FROM python:3.9
    
    WORKDIR /api_code
    
    # set environment variables
    ENV PYTHONDONTWRITEBYTECODE 1
    ENV PYTHONUNBUFFERED 1
    
    # install dependencies
    RUN pip install --upgrade pip
    
    COPY ./requirements.txt /api_code/requirements.txt
    
    # Install the package dependencies in the requirements file.
    RUN pip install --no-cache-dir --upgrade -r /api_code/requirements.txt
    
    RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends ffmpeg
    
    
    # torch
    torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cpu
    RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
    
    
    # whisper X
    RUN pip install git+https://github.com/m-bain/whisperx.git
    
    COPY ./app /api_code/app
    
    COPY ./logs /api_code/logs
    
    COPY ./celery_task_app /api_code/celery_task_app
    

    (3) Push to Azure Container Registry:

    #!/bin/sh
        
    set -e
    
    cat azure_pwd | docker login registry_name.azurecr.io -u 
    registry_name --password-stdin
    
    cd dir_to_push
    
    docker-compose build --pull
    
    echo -e "ndocker ps:n"
    
    docker ps
    
    echo -e "ndocker images:n"
    
    docker images
    
    echo -e "nRetag redis image:n"
    
    docker tag redis:7 
    registry_name.azurecr.io/repository_name:redis_app_2.4
    
    echo -e "ndocker images retagged:n"
    
    docker images
    
    echo -e "n Start push (except redis):n"
    
    docker-compose push
    
    echo -e "n Start push redis:n"
    
    docker push registry_name.azurecr.io/repository_name:redis_app_2.4
    

    (4) Azure yaml file for multicontainer web app:

    version: '3.8'
    
    services:
    
      web:
        image: # registry_path:tag (tag defines name in registry)  
            registry_name.azurecr.io/repository_name:web_app_2.4
        ports:
            # Host Port:Container Port
          - 80:8000
        command: uvicorn app.upload_file:app --host 0.0.0.0
        volumes:
          - type: bind
            source: ${WEBAPP_STORAGE_HOME}/site/wwwroot/wav_data
            target: /api_code/app/wav_data
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - redis
    
      
      worker:
        image: registry_name.azurecr.io/repository_name:worker_app_2.4
        command: > 
                 celery
                 --app=celery_task_app.worker.celery_app worker
                 --loglevel=info
                 --logfile=logs/celery.log
        volumes:
          - type: bind
            source: ${WEBAPP_STORAGE_HOME}/site/wwwroot/wav_data
            target: /api_code/app/wav_data
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
          - redis
    
      
      redis:
        image: registry_name.azurecr.io/repository_name:redis_app_2.4
    
      dashboard:
        image: registry_name.azurecr.io/repository_name:dashboard_app_2.4
        command: celery --broker=redis://redis:6379/0 flower --port=5555
        ports:
          - 443:5555
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
          - redis
          - worker
    

  2. 502 – Web server received an invalid response while acting as a gateway or proxy server

    This usually means that the application deployed in Azure App Service is not working as expected.

    • Here @Zori has also provided some valuable insights into the issues, In the presence of build: in the Azure docker-compose.yml removed the build: section from this file since Azure expects pre-built images.

    Expose these ports instead of port 8080.

    docker-compose.yml:

    services:
      web:
        ports:
          - 80:8080
    
    • Push the Redis image to the Azure Container Registry (ACR) with a specific tag.
    docker tag docker.io/redis:7 fastapiuploadfiles.azurecr.io/redis:7
    docker push fastapiuploadfiles.azurecr.io/redis:7
    

    docker-compose.yml

    version: '3.8'
    
    services:
    
      web:
        image: fastapiuploadfiles.azurecr.io/uploadfiles:web_app
        ports:
          - 80:8080
        command: uvicorn app.upload_file:app --host 0.0.0.0
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - redis
    
      worker:
        image: fastapiuploadfiles.azurecr.io/uploadfiles:worker_app
        command: celery --app=celery_task_app.worker.celery_app worker --loglevel=info --logfile=logs/celery.log
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
    
      redis:
        image: fastapiuploadfiles.azurecr.io/redis:7
    
      dashboard:
        image: fastapiuploadfiles.azurecr.io/uploadfiles:dashboard_app
        command: celery --broker=redis://redis:6379/0 flower --port=8080
        ports:
          - 8080:8080
        environment:
          - CELERY_BROKER_URL=redis://redis:6379/0
          - CELERY_RESULT_BACKEND=redis://redis:6379/0
        depends_on:
          - web
          - redis
    
    • You can check the images which had build successfully and pushed into the ACR.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search