I'm trying to run a simple NestJS app in Azure App Service on Linux. I've deployed the files to the server directly in wwwroot and I'm now trying to start it up using the startup command pm2 start main.js --no-daemon
.
The problem is that the service never actually finishes "warmup". The log stream also seems really weird. When I follow along with it it logs Waiting for response to warmup request for container
about every 15s. Then once it reaches the WEBSITES_CONTAINER_START_TIME_LIMIT
of 120s it suddenly logs every line of the boot process from my server including Application running on http://localhost:8080
as if everything works then immediately stops with Container [APP_NAME] for site [website-name] did not start within expected time limit
I can't seem to figure this out. It seems to start perfectly fine on the correct port (as far as I know), but only once the service stops. What am I doing wrong here?
The log seems to start with these lines (I say seems because the order of log statements differs every time I open the trace log view):
2022-03-10T12:51:44.202Z INFO - Starting container for site
2022-03-10T12:51:44.204Z INFO - docker run -d -p 8081:8081 --name [APP_NAME]_msiProxy -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=[HOST NAME] -e WEBSITE_INSTANCE_ID=[instance id] -e HTTP_LOGGING_ENABLED=1 [token service]
.395Z INFO - Starting container for site
2022-03-10T12:51:52.397Z INFO - docker run -d -p 8080:8080 --name [APP_NAME] -e WEBSITE_SITE_NAME=[website-name] -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=[HOST NAME] -e WEBSITE_INSTANCE_ID=[instance id] -e HTTP_LOGGING_ENABLED=1 appsvc/node:16-lts_20211110.1 pm2 start main.js --no-daemon
Edit: I've played around with the WEBSITES_CONTAINER_START_TIME_LIMIT
setting. It seems that no matter the value here the server will start, wait for this duration, then log the application startup lines and stop.
CodePudding user response:
So, it turns out the default docker image for Azure App Services is configured to only expose host 0.0.0.0
.
For NestJS I had to make the sure the app.listen
command explicitly listens on the address 0.0.0.0
like this:
const port = process.env.PORT || 3333
await app.listen(port, "0.0.0.0")
This allowed the app to boot and it's now responding fine :)
Big thanks to comment by Gupta for the tip that made everything work!
CodePudding user response:
From comments
Looks like the issue with Port
and IP
.
1- port 80 instead of 8000
.
2- set the app to listen on 0.0.0.0
.
Should work.