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?
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
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
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:
Use the EXPOSE instruction in your Dockerfile to expose port 3000.
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.
Related
I am trying to run Julia code in azure container app, but it fails for some reason.
docker file is pretty simple:
FROM julia:1.7-bullseye
COPY . /
EXPOSE 8080
RUN julia --project='/' -e 'using Pkg; Pkg.build()'
ENTRYPOINT julia --project='/' main.jl "0.0.0.0" "8080"
"0.0.0.0" and "8080" there is the host and port on which HTTP is served:
HTTP.serve(GENERAL_ROUTER, host, port_restful_api)
The app supposed to run a simple HTTP server that is served over port 8080, GET to / is the health check that returns simple "Up"
When I run that same image locally with docker run -p 8080:8080 my-test:latest it works fine and hitting localhost:8080 gives me my expected response
But when I have it in container app - revision fails to be provisioned (and no extra errors provided). In the ingress I added availability to accept traffic from anywhere and target port is 8080...
What I am missing?
UPDATE
At the same time in log analytics I can see my output to console that should indicate that the app is supposedly running fine, e.g.
[ Info: API handler service: Running on thread 1
In Julia those are done with
#info "API Server: Running on thread $(Threads.threadid())"
But in logs those are in stderr stream. Could it be that the ACA treats any output to stderr as startup error?
UPDATE 2:
The very same code works without any issues or changes on Azure Container Instance and in Azure Kubernetes Service...
So for now I stopped investigating and decided to use ACI.
You should verify if any process inside the julia image needs root privileges as ACA do not support running privileged containers based on the docs:
Azure Container Apps can't run privileged containers. If your program
attempts to run a process that requires root access, the application
inside the container experiences a runtime error.
Did you specify 8080 as your target port when configuring the HTTP ingress of your Container App? https://learn.microsoft.com/en-us/azure/container-apps/ingress?tabs=bash
The platform will try to ping your app at the specified port due to the default health probes. If it receives no response, it will restart your app: https://learn.microsoft.com/en-us/azure/container-apps/health-probes?tabs=arm-template
While trying to get Logux running in Cloud Run, I get this error:
Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
Even though the server is running an the Dockerfile is exposing the correct port (which is mapped in Cloud run as well).
The Dockerfile is located here: https://github.com/knownasilya/battle-chess/blob/main/Dockerfile
Note that the server runs https and ws on port 31337.
As mentioned by the Cloud Run Troubleshooting docs, if we get the message:
Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
And we know our code/container is working as expected, we should check that the port that that Cloud Run will be checking correlates with the one used in our app and like in this case, that the container listens on 0.0.0.0 (all the net interfaces)
As well this is mentioned in the Cloud Run Requirements doc:
The container must listen for requests on 0.0.0.0 on the port to which requests are sent. By default, requests are sent to 8080, but you can configure Cloud Run to send requests to the port of your choice. Cloud Run injects the PORT environment variable into the container. Inside Cloud Run container instances, the value of the PORT environment variable always reflects the port to which requests are sent. It defaults to 8080.
First of all, I am aware that there are a few similar questions and I have tried the suggestions in the answers provided, but it did not help.
I have an ASP.NET Core web app running as a Linux container. Locally the app builds and runs fine.
When deployed to Azure, the app fails to start up and I can see the following error:
Container mytestapp_0_560a15e8 for site mytestapp did not start within expected time limit. Elapsed time = 230.4559912 sec
Container mytestapp_0_560a15e8 didn't respond to HTTP pings on port: 8600, failing site start. See container logs for debugging.
Stopping site mytestapp because it failed during startup.
-ERROR - Container mytestapp_0_74c5b4f4 for site mytestapp did not start within expected time limit. Elapsed time = 1800.0389751 sec
(Notice I tried increasing the WEBSITES_CONTAINER_START_TIME_LIMIT to maximum value (after reading this) and I did set the WEBSITES_PORT settings to use 8600 instead of default 80 after reading this and this)
My dockerfile exposes port 8600 as below:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
ARG port
WORKDIR /app
EXPOSE ${port:-8600}
and it seems to run OK
docker run -d -p 8266:8600 --name mytestapp_0_560a15e8 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8600 -e WEBSITE_SITE_NAME=mytestapp -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=mytestapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=cb8d91c9d2a29a2894b5445bbfe9d306e91eb996b4b7cdada5ff30dc3f2bfdda -e HTTP_LOGGING_ENABLED=1 myregistry.azurecr.io/lc-mytestapp-addon:1.2.59
One more thing that I tried is that when I expose port 80 in the dockerfile (and disable the WEBSITES_PORT setting in Azure), the app runs OK.
Am I doing anything wrong with the exposure of port 8600, or is it just a limitation that I have to live with?
Try adding an app setting of PORT set to 8600 as well as WEBSITES_PORT.
App Service only serves traffic on port 80. The WEBSITES_PORT setting allows you to map incoming traffic on port 80 to the port that your container is listening on. Therefore, there is no way to reach your container directly using port 8600.
I'm running into an annoying issue where my containerized app runs fine locally, but fails when deployed to azure, despite the ports being exposed properly.
The details:
azure web app for container with Linux OS on a Basic B1 machine.
nodejs v12 LTS with express server listening on HTTPS port 443. Includes an HTTP 404 (Not Found) error handler.
database db Mongodb Atlas on M0 Sandbox (free tier). Local and Azure IPs whitelisted.
docker container using Dockerfile. no Kubernetes, no yml config file.
docker image hosted on private Docker Hub repo, pulled by azure on build
Running locally on Windows 10 x64:
without docker:
node app.js
runs fine via https://localhost:443
with docker:
docker build -t myapp:latest . then
docker run -p 49160:443 -d myapp:latest
runs fine via https://localhost:49160
In both cases I get the expected output from my nodejs app:
Running in production on x64
Express HTTPS server listening on port 443
mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
(obvously, myapp and mydb are not the actual names. Used here for convenience.)
Running in azure:
Under Configuration -> Application settings:
PORT=443
WEBSITES_PORT=443
DOCKER_ENABLE_CI=true
Pipeline set up pulling docker image myrepo/myapp:latest from private Docker Hub repo on build. Image is pulled correctly.
Fails via https://myapp.azurewebsites.net/ with error 503 Service Temporarily Unavailable.
Azure log:
2020-04-10 18:02:21.040 INFO - Pulling image: myrepo/myapp:latest
2020-04-10 18:02:22.128 INFO - latest Pulling from myrepo/myapp
2020-04-10 18:02:22.129 INFO - Digest: sha256:982[...]
2020-04-10 18:02:22.129 INFO - Status: Image is up to date for myrepo/myapp:latest
2020-04-10 18:02:22.131 INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2020-04-10 18:02:22.143 INFO - Starting container for site
2020-04-10 18:02:22.144 INFO - docker run -d -p 7909:443 --name myapp_0_138f197c -e PORT=80 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=443 -e WEBSITE_SITE_NAME=myapp -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=myapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=6fc3[...] myrepo/myapp:latest
2020-04-10 18:02:22.144 INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-04-10 18:02:23.473 INFO - Initiating warmup request to container myapp_0_138f197c for site myapp
2020-04-10 18:02:45.304 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 21.8308149 sec
[...]
2020-04-10 18:06:08.252 INFO - Waiting for response to warmup request for container myapp_0_138f197c. Elapsed time = 224.7791547 sec
2020-04-10T18:02:24.893958779Z Running in production on x64
2020-04-10T18:02:26.275376640Z Express HTTPS server listening on port 80
2020-04-10T18:02:26.601261213Z mongo :: connected to database mydb at mydb-tot7b.azure.mongodb.net
2020-04-10 18:06:14.346 ERROR - Container myapp_0_138f197c for site myapp did not start within expected time limit. Elapsed time = 230.8732099 sec
2020-04-10 18:06:14.365 ERROR - Container myapp_0_138f197c didn't respond to HTTP pings on port: 443, failing site start. See container logs for debugging.
2020-04-10 18:06:14.427 INFO - Stoping site myapp because it failed during startup.
Why the containerized app seems to start correctly, as seen in the azure log, but the container fails to respond to HTTP ping on 443, which is exposed both in dockerfile and in azure with PORT and WEBSITES_PORT?
Do I need to make my HTTPS server explicitly respond to HTTP PING and if so, how do I do it?
Dockerfile:
FROM node:12
WORKDIR /usr/src/myapp
COPY package*.json ./
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
RUN npm install
COPY . .
EXPOSE 443
CMD [ "node", "app.js" ]
This issue might be considered a duplicate, but I provide a lot more relevant information, compared to most of the issues below. Also, I spent significant time in troubleshooting and none of these relevant resources seemed to help:
Docker never runs on Azure - Waiting for response to warmup request for container
Azure Web App on Linux: "Error: Container didn't respond to HTTP pings on port: 8080" - when using: "start": "pm2 start server.js"
How do you expose port 3000 using an Azure Web App Container?
https://superuser.com/questions/1479521/i-cannot-create-a-node-js-web-app-to-be-deployed-on-azurer
https://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#troubleshootingr
https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#troubleshootingr
https://learn.microsoft.com/en-us/azure/app-service/containers/configure-language-nodejsr
https://github.com/MicrosoftDocs/azure-docs/issues/46401r
https://github.com/MicrosoftDocs/azure-docs/issues/34451r
https://omgdebugging.com/2017/12/22/azure-web-app-for-container-failing-site-start/r
https://devops.stackexchange.com/questions/4543/how-to-debug-a-docker-on-web-app-for-containers-in-azure-which-does-not-startr
https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-faq#custom-containersr
Running a docker container in Azure web app: didn't respond to HTTP pings on port
Docker Container fails to start in an Azure App Service
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-troubleshootingr
https://serverfault.com/questions/1003418/azure-docker-app-error-site-did-not-start-within-expected-time-limit-and-cor
https://medium.com/#sergiibielskyi/azure-event-hub-listener-in-the-container-dd6f8d053814r
When enforcing HTTPS at the App Service level, TLS termination will happen and traffic will be routed to your container port so there's no need to enforce TLS from your container.
If your container listens on another port (ex: 8081), simply set the WEBSITES_PORT application setting to that port number. App Service will listen on port 80 and forward traffic to your container port.
My own app had been doing app.UseHttpsRedirection() in Startup.Configure. That was the cause of this error for me. As soon as I stopped doing that, the problem went away.
I think I am also facing similar issue and in my case I can't changed the source code for application to run on http.
We have a very basic requirement, wherein there is an API build on ASP.NET Core running on specific port (say 11000), and served only on HTTPS, i.e http traffic is disabled, and the API is rendered on custom domain, (on local machine it is achieved through host file entries).
Working on POC to deploy this API on Docker container on Azure App service. Running this setup on local system and it works perfectly fine.
Steps followed.
Compose build
Create Image
Tag this Image
Push this image to Azure Container Register
Set the correct values in Deployment Center
Add the Application Settings for WEBSITES_PORT and set its value to the port, 11000.
While starting the container in Azure it is throwing error as
28/06/2022 18:40:04.370 INFO - Site: XXXXXXXXXXXXXX-webapp - [
some-alpha-numeric-identifier] - Waiting for container to be ready.
Container Id: some-alpha-numeric-identifier
And the I know the reason for the error, while starting the container is connecting to http://127.0.0.1:11000 and the base application only listens on https, I need to know how to overcome this error, can we for the app service to connect to the base docker image only over https.
I tried deploying a simple node js service in azure ubuntu using CLI,console logs says the server is up on port 8080(this same service works perfectly in my local machine),but when i tried to access the public ip from outside,it gives site can't be reached
Following was the output when i deployed my service
azureuser#myVM:~/drugdemo/user_service/drulistService$ vi server.js
azureuser#myVM:~/drugdemo/user_service/drulistService$ node server.js
App is listening on 8080
^C^C
azureuser#myVM:~/drugdemo/user_service/drulistService$ pm2 start server.js
[PM2] Starting
/home/azureuser/drugdemo/user_service/drulistService/server.js in fork_mode (1 instance)
[PM2] Done.
Use `pm2 show <id|name>` to get more details about an app
azureuser#myVM:~/drugdemo/user_service/drulistService$
Please help me with your suggections.
(I already tried changing 'localhost' to '0.0.0.0' and '127.0.0.1' but didn't work for me)
Thank you in advance
Make sure to open the firewall port via Azure as well and not just the server.
This may help: https://blogs.msdn.microsoft.com/pkirchner/2016/02/02/allow-incoming-web-traffic-to-web-server-in-azure-vm/