skip to Main Content

I’m facing issues with my Python Flask web app when deploying it on Azure. I followed the documentation and set up a Dockerfile, but I am encountering problems when trying to access the deployed application. Below are the relevant details:

Dockerfile:

# Use the Azure Web App Python base image
FROM python:3.10

# Set the working directory in the container
WORKDIR /app

# Install FFmpeg
RUN apt-get update && apt-get install -y ffmpeg

# Upgrade pip to the latest version
RUN pip install --no-cache-dir --upgrade pip

# Copy the requirements file and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the Flask app code into the container
COPY . .

# Expose the port your Flask app runs on (usually 5000)
EXPOSE 5000

# Define the command to run your Flask app
CMD ["python", "application.py"]

Relevant part of application.py:

if __name__ == "__main__":
    application.run(host="0.0.0.0", debug=True)

Log Stream:

...
2023-10-09T00:27:21  Welcome, you are now connected to log-streaming service.
Starting Log Tail -n 10 of existing logs ----/home/LogFiles/__lastCheckTime.txt  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/__lastCheckTime.txt)10/09/2023 00:08:05/home/LogFiles/kudu/trace/6335909c4eec-d1c787cf-5978-4748-afeb-2b0b5b9c5589.txt  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/6335909c4eec-d1c787cf-5978-4748-afeb-2b0b5b9c5589.txt)
2023-10-09T00:27:16  Startup Request, url: /api/deployments/?$orderby=ReceivedTime%20desc&$top=20&api-version=2022-03-01, method: GET, type: request, pid: 87,1,17, ScmType: None/home/LogFiles/kudu/trace/919d9d74f6c7-77f73535-a8c4-48e4-b86b-073c82a6b091.txt  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/919d9d74f6c7-77f73535-a8c4-48e4-b86b-073c82a6b091.txt)
2023-10-08T21:13:48  Startup Request, url: /api/deployments/?$orderby=ReceivedTime%20desc&$top=20&api-version=2022-03-01, method: GET, type: request, pid: 86,1,5, ScmType: None
/home/LogFiles/kudu/trace/f0fe9017da97-288a89c3-1a7d-4301-9bae-5383548afdae.txt  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/f0fe9017da97-288a89c3-1a7d-4301-9bae-5383548afdae.txt)
2023-10-08T21:15:20  Startup Request, url: /api/logstream/, method: GET, type: request, pid: 93,1,5, ScmType: None/home/LogFiles/2023_10_08_lw1sdlwk00003N_default_docker.log  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/2023_10_08_lw1sdlwk00003N_default_docker.log)
2023-10-08T21:18:00.727101619Z exec /usr/local/bin/python: exec format error
/home/LogFiles/2023_10_08_lw1sdlwk00003N_docker.log  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/2023_10_08_lw1sdlwk00003N_docker.log)
2023-10-08T23:59:57.351Z INFO  - 5b6cc8d80836 Extracting 34MB / 182MB
2023-10-08T23:59:57.734Z INFO  - 5b6cc8d80836 Extracting 37MB / 182MB
2023-10-08T23:59:57.894Z INFO  - 5b6cc8d80836 Extracting 38MB / 182MB
2023-10-08T23:59:58.165Z INFO  - 5b6cc8d80836 Extracting 40MB / 182MB
2023-10-08T23:59:58.327Z INFO  - 5b6cc8d80836 Extracting 41MB / 182MB
2023-10-08T23:59:58.836Z INFO  - 5b6cc8d80836 Extracting 44MB / 182MB
2023-10-08T23:59:58.938Z INFO  - 5b6cc8d80836 Extracting 44MB / 182MB
2023-10-08T23:59:59.057Z INFO  - 5b6cc8d80836 Extracting 45MB / 182MB
2023-10-08T23:59:59.627Z INFO  - 5b6cc8d80836 Extracting 47MB / 182MB
2023-10-08T23:59:59.789Z INFO  - 5b6cc8d80836 Extracting 48MB / 182MB/home/LogFiles/2023_10_09_lw1sdlwk00003N_default_docker.log  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/2023_10_09_lw1sdlwk00003N_default_docker.log)
2023-10-09T00:00:42.275260288Z exec /usr/local/bin/python: exec format error
2023-10-09T00:03:06.223995155Z exec /usr/local/bin/python: exec format error
2023-10-09T00:05:39.529100248Z exec /usr/local/bin/python: exec format error
2023-10-09T00:08:06.612760325Z exec /usr/local/bin/python: exec format error
/home/LogFiles/2023_10_09_lw1sdlwk00003N_docker.log  (https://talktotexts.scm.azurewebsites.net/api/vfs/LogFiles/2023_10_09_lw1sdlwk00003N_docker.log)
2023-10-09T00:08:05.805Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2023-10-09T00:08:05.889Z INFO  - Starting container for site
2023-10-09T00:08:05.890Z INFO  - docker run -d --expose=5000 --name talktotexts_0_0932adae -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=talktotexts -e WEBSITE_AUTH_ENABLED=False -e PORT=5000 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=talktotexts.azurewebsites.net -e WEBSITE_INSTANCE_ID=6112ee766f20dedb21a683a179ca760b2a33a00f96b3c2626bbc09e4e42eace6 -e WEBSITE_USE_DIAGNOSTIC_SERVER=False talktotext.azurecr.io/talktotext:latest
2023-10-09T00:08:05.891Z INFO  - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2023-10-09T00:08:07.164Z INFO  - Initiating warmup request to container talktotexts_0_0932adae for site talktotexts
2023-10-09T00:08:22.440Z ERROR - Container talktotexts_0_0932adae for site talktotexts has exited, failing site start
2023-10-09T00:08:22.446Z ERROR - Container talktotexts_0_0932adae didn't respond to HTTP pings on port: 5000, failing site start. See container logs for debugging.
2023-10-09T00:08:22.454Z INFO  - Stopping site talktotexts because it failed during startup.Ending Log Tail of existing logs ---Starting Live Log Stream ---
...

When I access my Azure Web App’s domain, I get the following error message:

Error when going on domain:

:( Application Error
If you are the application administrator, you can access the diagnostic resources.

How can I make my Flask app accessible from the internet when deployed on Azure? Any insights into the errors in my logs would be greatly appreciated.

Additionally, please note that my Docker image is pushed to the Azure Container Registry (ACR).

2

Answers


  1. Chosen as BEST ANSWER

    I successfully deployed my Docker container to Azure Container Apps using the valuable guidance provided in this informative article:

    Link to the Article

    One key aspect of the article that greatly facilitated my deployment process was the utilization of the az containerapp up command. This single command streamlined the entire deployment process, making it straightforward and efficient.

    az containerapp up 
      -g flask-aca-rg 
      -n flask-aca-app 
      --ingress external 
      --target-port 5000 
      --source .
    

    Let me break down what this command accomplishes:

    • Creation of a Resource Group: It establishes an Azure resource group, which serves as an organizational entity for managing resources during deployment.

    • Provisioning of a Container App Environment: This command sets up a Container App Environment and Log Analytics workspace within the specified resource group.

    • Docker Image Build: It automates the Docker image building process by utilizing the local Dockerfile.

    • Image Push to Azure Container Registry: The command creates a registry in the Azure Container Registry and then pushes the Docker image to that registry.

    • Creation of the Container App: It configures a Container App with the pushed image, allowing external access on a specified port.

    Executing this command from my project's root directory enabled me to deploy my Flask application effortlessly. The beauty of this approach is that whenever I made updates to my application code, I could simply rerun the same command to update the app.

    Both the article and the az containerapp up command proved to be instrumental in simplifying the deployment process, freeing me to focus on developing my Flask application. If you are considering deploying your Flask application on Azure Container Apps, I highly recommend referring to the article for a detailed, step-by-step guide. Additionally, I integrated CI/CD through GitHub Actions to automate the deployment process, ensuring that my Docker container is automatically deployed every time a change is made to the codebase. This further streamlines the development and deployment workflow.


  2. Here are some possible scenarios.

    • Firewall: Your app is not accessible by your IP. Check if incoming traffic is allowed from public addresses.

    • Host: Try running your app on 127.0.0.1 instead of 0.0.0.0

    • Port: In networking, check inbound rules, and open port 5000. By default Azure blocks all ports other than 22, 80, 443.

    These are few things you can try based on the information you shared, though it can be something else as well.

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