0

I'm trying a simple NextJS server in an Azure AppService, and the container fails to start, even though the logs indicate that NextJS is up and ready to server files. The code works fine locally.

My code is here: https://github.com/CutieDarkFae/Catz

The container log finishes with:

***2020-06-11T08:43:19.032969810Z Extracting modules...
2020-06-11T08:43:44.262867136Z Done.
2020-06-11T08:43:45.328947365Z 
2020-06-11T08:43:45.328985465Z > cats@0.1.0 start /home/site/wwwroot
2020-06-11T08:43:45.328992064Z > next start
2020-06-11T08:43:45.328996364Z 
2020-06-11T08:43:47.016355156Z ready - started server on http://localhost:3000***

But the AppService logs end with:

2020-06-11T08:46:44.113Z INFO  - Waiting for response to warmup request for container catz_0_39a9d511. Elapsed time = 210.9209243 sec
2020-06-11T08:46:59.249Z INFO  - Waiting for response to warmup request for container catz_0_39a9d511. Elapsed time = 226.0570954 sec
2020-06-11T08:47:03.323Z ERROR - Container catz_0_39a9d511 for site catz did not start within expected time limit. Elapsed time = 230.1311154 sec
2020-06-11T08:47:03.326Z ERROR - Container catz_0_39a9d511 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2020-06-11T08:47:03.342Z INFO  - Stopping site catz because it failed during startup.

How can I get the container to notice that the app is up and running? and not to time out?

Or is an AppService the wrong place to put a NextJS server?

Pranav Choudhary
  • 2,726
  • 3
  • 18
  • 38

3 Answers3

0

It looks like your app is starting on port 3000 but the App Service is expecting it on port 8080.

Set the app setting WEBSITES_PORT to 3000. https://learn.microsoft.com/en-us/azure/app-service/containers/configure-custom-container

silent
  • 14,494
  • 4
  • 46
  • 86
0

The suggestion here didn't work for me alas, it kept trying on 8080 no matter what :(

What did work is the approved answer here: unable to deploy next js to azure

I would have preferred a much simpler solution though

0

As Silent mentioned. Kindly use app setting WEBSITES_PORT to set the port for your own docker image while for blessed images use PORT environment variable as the listening port.

In your application, please use the PORT or WEBSITES_PORT (as applicable) environment variable as the main web server’s listening port, instead of using a hardcoded port number ( on app start-up on locahost:3000). The PORT environment variable is automatically set by App Service platform at startup time.

As mentioned, you could try these ways:

  1. Use the EXPOSE instruction in your Dockerfile to expose port 3000.
  2. Use the WEBSITES_PORT app setting with a value of "3000" to expose that port.

If the issue still persist, just to isolate, you could change the script to - "/home/site/wwwroot/node_modules/next/dist/bin/next start" and change the change the port 80 and see if that helps.

AjayKumar
  • 2,812
  • 1
  • 9
  • 28
  • As I said in my comment below (I thought I was replying, sorry) setting WEBSITES_PORT had no effect. I don't have a docker file, I have what's in the repository above. I'm pushing code up to Azure, Azure is building the docker image. What script are you referring to when you say 'change the script'? Again, I have what's in the repository listed in my question. – Cutie DarkFae Jun 15 '20 at 05:11