2

I am trying to publish my web app to Azure, but it fails when I try to connect.

The app service plan I am deploying to is B1 (basic tier) with a Linux OS. I only have one app on the plan. Azure launches my app inside of a docker container. I'm using one of the prebuilt docker container images that Azure allowed me to select when I created the app. It comes with Python installed. I configured it to run my startup.sh file.

app service settings

I also added some variables under Configuration > Application settings:

DJANGO_SETTINGS_MODULE mywebsite.settings
PORT 8000
PYTHONUNBUFFERED 1
WEBSITE_HTTPLOGGING_RETENTION_DAYS 3
WEBSITES_PORT 8000

I publish the app with these two commands:

az login
az webapp up --resource-group myresourcegroup --location mylocation --plan ASP-myresourcegroup-blah --sku B1 --name mywebsite

These commands succeed, but my app fails when I connect.

application error

My startup.sh file has two commands inside:

pip install -r requirements.txt
python manage.py runserver

The logs show the startup commands run and complete successfully, and that the website started successfully and is listening on port 8000, but then when Azure tries to ping my web app on that very same port, it says that it didn't get a response. Here are the logs (notice they are out of timestamp order... this is how they appeared in the log stream):

2020-12-16T02:20:04.585Z INFO  - Waiting for response to warmup request for container mywebsite_0_d3b33c19. Elapsed time = 172.6836952 sec
2020-12-16T02:20:19.856Z INFO  - Waiting for response to warmup request for container mywebsite_0_d3b33c19. Elapsed time = 187.9540221 sec
2020-12-16T02:20:35.651Z INFO  - Waiting for response to warmup request for container mywebsite_0_d3b33c19. Elapsed time = 203.749022 sec
2020-12-16T02:20:50.800Z INFO  - Waiting for response to warmup request for container mywebsite_0_d3b33c19. Elapsed time = 218.8978635 sec
2020-12-16T02:17:12.000537617Z
2020-12-16T02:17:12.000577119Z   _____
2020-12-16T02:17:12.000583719Z   /  _  \ __________ _________   ____
2020-12-16T02:17:12.000587719Z  /  /_\  \___   /  |  \_  __ \_/ __ \
2020-12-16T02:17:12.000591720Z /    |    \/    /|  |  /|  | \/\  ___/
2020-12-16T02:17:12.000595720Z \____|__  /_____ \____/ |__|    \___  >
2020-12-16T02:17:12.000599720Z         \/      \/                  \/
2020-12-16T02:17:12.000603720Z
2020-12-16T02:17:12.000607120Z A P P   S E R V I C E   O N   L I N U X
2020-12-16T02:17:12.000610920Z
2020-12-16T02:17:12.000614320Z Documentation: http://aka.ms/webapp-linux
2020-12-16T02:17:12.000617821Z Python 3.8.6
2020-12-16T02:17:12.000621321Z Note: Any data outside '/home' is not persisted
2020-12-16T02:17:12.198388052Z Starting OpenBSD Secure Shell server: sshd.
2020-12-16T02:17:12.252715076Z Site's appCommandLine: startup.sh
2020-12-16T02:17:12.260128166Z Checking of startup.sh is a file
2020-12-16T02:17:12.263732107Z App command line is a file on disk
2020-12-16T02:17:12.282773551Z App command line is a shell script, will execute this script as startup script
2020-12-16T02:17:12.282788052Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand startup.sh
2020-12-16T02:17:12.347943299Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2020-12-16T02:17:12.348640026Z Could not find operation ID in manifest. Generating an operation id...
2020-12-16T02:17:12.348651527Z Build Operation ID: 2c77a144-4474-47e4-8aa3-1f4ff3c198eb
2020-12-16T02:17:13.168737187Z Oryx Version: 0.2.20201112.1, Commit: a120bb248aa8d208ca5e02d7d9d075196e79cffd, ReleaseTagName: 20201112.1
2020-12-16T02:17:13.410183127Z Writing output script to '/opt/startup/startup.sh'
2020-12-16T02:17:14.066570788Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2020-12-16T02:17:14.067184412Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2020-12-16T02:17:15.739535928Z Collecting asgiref==3.2.10
2020-12-16T02:17:15.826655271Z   Downloading asgiref-3.2.10-py3-none-any.whl (19 kB)
2020-12-16T02:17:16.386265926Z Collecting Django==3.1.1
2020-12-16T02:17:16.417033854Z   Downloading Django-3.1.1-py3-none-any.whl (7.8 MB)
2020-12-16T02:17:22.371919755Z Collecting pytz==2020.1
2020-12-16T02:17:22.400840533Z   Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
2020-12-16T02:17:22.880103926Z Collecting sqlparse==0.3.1
2020-12-16T02:17:22.916370202Z   Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
2020-12-16T02:17:23.118180495Z Collecting typing-extensions==3.7.4.3
2020-12-16T02:17:23.141494644Z   Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
2020-12-16T02:17:23.621018444Z Installing collected packages: asgiref, sqlparse, pytz, Django, typing-extensions
2020-12-16T02:17:33.600193355Z Successfully installed Django-3.1.1 asgiref-3.2.10 pytz-2020.1 sqlparse-0.3.1 typing-extensions-3.7.4.3
2020-12-16T02:17:34.110375763Z WARNING: You are using pip version 20.2.4; however, version 20.3.3 is available.
2020-12-16T02:17:34.110400964Z You should consider upgrading via the '/opt/python/3.8.6/bin/python3.8 -m pip install --upgrade pip' command.
2020-12-16T02:17:37.837917973Z Watching for file changes with StatReloader
2020-12-16T02:17:37.839415012Z Performing system checks...
2020-12-16T02:17:37.839427112Z
2020-12-16T02:17:38.033620729Z System check identified no issues (0 silenced).
2020-12-16T02:17:38.070782408Z December 16, 2020 - 02:17:38
2020-12-16T02:17:38.071496227Z Django version 3.1.1, using settings 'mywebsite.settings'
2020-12-16T02:17:38.071509227Z Starting development server at http://127.0.0.1:8000/
2020-12-16T02:17:38.071513927Z Quit the server with CONTROL-C.
2020-12-16T02:21:02.907Z ERROR - Container mywebsite_0_d3b33c19 for site mywebsite did not start within expected time limit. Elapsed time = 231.0048832 sec
2020-12-16T02:21:02.923Z ERROR - Container mywebsite_0_d3b33c19 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2020-12-16T02:21:02.936Z INFO  - Stopping site mywebsite because it failed during startup.

There seems to be a contradiction between "Starting development server at http://127.0.0.1:8000/" and "didn't respond to HTTP pings on port: 8000". How can my website be running on port 8000 but not responding to HTTP pings on the same port?

This question links to a lot of relevant material, but none of it helped me. I don't have my own dockerfile like many of those people do, and at least according to my logs, my docker container starts up just fine.

Rainbolt
  • 3,542
  • 1
  • 20
  • 44
  • "starting" != "started". Your site failed to start. – Jared Smith Dec 16 '20 at 03:11
  • @JaredSmith You can tell it finished starting because of the message that follows, "Quit the server with CONTROL-C". – Rainbolt Dec 16 '20 at 03:18
  • 127.0.0.1 is listening only on local interface try 0.0.0.0 instead. Also runserver is not intended to be used in production https://docs.djangoproject.com/en/3.1/ref/django-admin/#runserver – iklinac Dec 16 '20 at 04:07
  • Do you try to set your host as 0.0.0.0 in your code or when run the application via the command in the startup script? – Charles Xu Dec 21 '20 at 02:38
  • @CharlesXu Setting `ALLOWED_HOSTS = ['*']` in mywebsite/settings.py solved the problem. I know it's not best practice to use wildcard, but I haven't figured out the correct values to put there yet. – Rainbolt Dec 21 '20 at 14:32
  • 1
    I set the host as 0.0.0.0 for the flask and it works fine. So I think it's also useful for Django. – Charles Xu Dec 22 '20 at 01:40

0 Answers0