deploying the python webapp which need to host two services (like streamlit and flask) using one container image

Pavan Naga 0 Reputation points
2023-10-27T10:46:38.59+00:00

hello, i created a streamlit application which uses flaskapi. so when i run it in my local device

docker run -p 8880:8501 -p 5000:5000 webapp

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.


  You can now view your Streamlit app in your browser.

  URL: http://0.0.0.0:8501

2023-10-27 10:41:14.010
  Warning: to view this Streamlit app on a browser, run it with the following
  command:

    streamlit run /usr/local/bin/flask [ARGUMENTS]
2023-10-27 10:41:14.013 Session state does not function when running a script without `streamlit run`
 * Serving Flask app 'app.py'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
 * Running on http://172.17.0.2:5000
Press CTRL+C to quit

like this it hosts the both streamlit in port 8501 and flask in port 5000

so what i want to know is, how can i manage the ports in azure when i try to deploy this docker container image. like both streamlit and flask cant listen on same port. so if 80 and 8081 are available in azure. i want to assign 80:8501 and 8081:5000. so that both flask and streamlit work fine. i want to know how to do this

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-10-31T04:07:58.7666667+00:00

    @Pavan Naga To configure the ports for your custom container in Azure App Service, you can set the WEBSITES_PORT app setting in your App Service app. By default, App Service assumes your custom container is listening on port 80. If your container listens to a different port, you can set the WEBSITES_PORT app setting to the port number that your container is listening on.

    For example, if you want to map port 80 to port 8501 for your Streamlit app and port 8081 to port 5000 for your Flask API, you can set the WEBSITES_PORT app setting to 8501 for your Streamlit app and 5000 for your Flask API.

    You can set the WEBSITES_PORT app setting via the Azure Cloud Shell. In Bash:

    <span class=" active-doc-0 active-doc-2" data-doc-items="0,2">az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings WEBSITES_PORT=8501<a href="#doc-pos=0" data-tag-index="1"></a><a href="#doc-pos=2" data-tag-index="2"></a></span>
    <pre data-lang=""><code>
    In PowerShell:
    
    ```azurepowershell-interactive
    <span class=" active-doc-0" data-doc-items="0">Set-AzWebApp -ResourceGroupName <group-name> -Name <app-name> -AppSettings @{"WEBSITES_PORT"="8501<a href="#doc-pos=0" data-tag-index="1"></a></span>"}
    </code></pre>
    <span class=" active-doc-0" data-doc-items="0">You can also set the `WEBSITES_PORT` app setting in the Azure portal<a href="#doc-pos=0" data-tag-index="1"></a></span>. To do this, go to your App Service app in the Azure portal, click on "Configuration" under "Settings", and add a new application setting with the name `WEBSITES_PORT` and the value `8501` for your Streamlit app and `5000` for your Flask API.
    
    Once you have set the `WEBSITES_PORT` app setting for your App Service app, Azure App Service will route incoming traffic on port 80 to port 8501 for your Streamlit app and incoming traffic on port 8081 to port 5000 for your Flask API.
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.