Anup
Anup

Reputation: 41

Docker container not responding on azure web app

I'm trying to deploy and run a spring boot app on azure linux web app using azure devops pipeline. The container is getting deployed on web app however it is not responding to health checks after it starts. In deployment, az-pipeline yml file build's jar package using Maven then builds image and pushes to ACR. Webhook deploys latest image to web app.

Errors

 - docker run -d -p 8440:8000 --name myapp-backend-dev_0_2b7b9f65 -e
   WEBSITE_CORS_ALLOWED_ORIGINS=* -e
   WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e
   WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8000 -e
   WEBSITE_SITE_NAME=myapp-backend-dev -e WEBSITE_AUTH_ENABLED=False -e
   WEBSITE_ROLE_INSTANCE_ID=0 -e
   WEBSITE_HOSTNAME=myapp-backend-dev.azurewebsites.net -e
   WEBSITE_INSTANCE_ID=0d7eaa93ccf04e2494816f0f168f4e2170cd80b95a36687e39877b27289
   -e HTTP_LOGGING_ENABLED=1 myappdevacr.azurecr.io/dev:latest
   2. Starting container for site
   3. docker run -d -p 9268:8081 --name myapp-backend-dev_0_2b7b9f65_middleware -e
   WEBSITE_CORS_ALLOWED_ORIGINS=* -e
   WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e
   WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITES_PORT=8000 -e
   WEBSITE_SITE_NAME=myapp-backend-dev -e WEBSITE_AUTH_ENABLED=False -e
   WEBSITE_ROLE_INSTANCE_ID=0 -e
   WEBSITE_HOSTNAME=myapp-backend-dev.azurewebsites.net -e
   WEBSITE_INSTANCE_ID=0d7eaa93ccf04e2494816f0f168f4e2170cd80b95a36687e39877b27289
   -e HTTP_LOGGING_ENABLED=1 appsvc/middleware:1907112318 /Host.ListenUrl=http://0.0.0.0:8081
   /Host.DestinationHostUrl=http://172.16.1.2:8000
   /Host.UseFileLogging=true
   4. Container myapp_0_de5443dd didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
   5. home/LogFiles/webssh/pm2.log (https://myapp.scm.azurewebsites.net/api/vfs/LogFiles/webssh/pm2.log)Host:
   undefinedwebssh2 Login: user=root from=127.0.0.1 host=undefined
   port=2222 sessionID=undefined allowreplay=undefinedHeaders:
   {"connection":"close","accept":"text/html, application/xhtml+xml,
   application/xml; q=0.9, /;
   q=0.8","accept-encoding":"br, gzip,
   deflate","accept-language":"en-gb","cookie":"ARRAffinity=0d7eaa93ccf04e2494816f0f168f4e2170cd80b95a36687e39877b2728981272","host":"127.0.0.1:3000","max-forwards":"10","referer":"https://myapp.scm.azurewebsites.net/","user-agent":"Mozilla/5.0
   (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like
   Gecko) Version/12.1.2
   Safari/605.1.15","x-client-ip":"111.11.111.111","x-client-port":"57208","x-waws-unencoded-url":"/webssh/host","client-ip":"111.11.111.111:57208","x-arr-log-id":"SOMETHING-ee62-48cf-813a-724c9acb0ca0","disguised-host":"myapp.scm.azurewebsites.net","x-site-deployment-id":"myapp","was-default-hostname":"myapp.scm.azurewebsites.net","x-original-url":"/webssh/host","x-ms-client-principal-name":"[email protected]","x-ms-client-display-name":"SOME
   NAME","x-forwarded-for":"111.11.111.111:57208","x-arr-ssl":"2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT,
   CN=Microsoft IT TLS CA
   5|CN=*.azurewebsites.net","x-forwarded-proto":"https","x-appservice-proto":"https"}Host
   from file: 172.16.1.2DEBUG: Local ident:
   'SSH-2.0-ssh2js0.1.16'on.error - Error: connect ECONNREFUSED
   172.16.1.2:2222Status_WatchFile :: Error Error: ENOENT: no such file or directory, open '/appsvctmp/status.txt'

Dockerfile

FROM adoptopenjdk/openjdk11:ubi

ARG PROFILE
ENV spring.profiles.active=$PROFILE

ENV ACCEPT_EULA=Y ENV WEBSITES_PORT=8000 ENV WEBSITE_HTTPLOGGING_RETENTION_DAYS=7 ENV WEBSITES_CONTAINER_START_TIME_LIMIT=1800

ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar

EXPOSE 8000 8000
ENTRYPOINT ["java","-jar","/app.jar"]

NOTE: Tried solution provided by Charles Xu and beerzy on this post but the error didn't resolve.

Upvotes: 0

Views: 2439

Answers (2)

Shrirang - Microsoft
Shrirang - Microsoft

Reputation: 99

It appears you are trying to deploy your Java 11 application as a Linux web app to Azure App Service. To do this you can directly deploy your jar to the web app without having to build a Docker image. This will also save you additional work of maintaining ACR and configuring web hooks.

There are various ways to deploy your application to the web app. As you are already using Maven in your pipeline, the easiest for you will be to use the azure-webapp-maven plugin to deploy your app to Azure App Service. Check this article for details: https://learn.microsoft.com/en-us/azure/java/spring-framework/deploy-spring-boot-java-app-with-maven-plugin. The example in this article uses Java 8. To use Java 11, change javaVersion and webContainer to java11 instead of jre8. App Service will automatically take care of setting the appropriate SERVER_PORT environment variable behind the scenes, so that when your Spring Boot application starts, it will start listening to the correct port (which is what your original question was).

You can define Java properties using JAVA_OPTS in the <appSettings> tag in pom.xml. Refer the above article for an example. Just make sure that you don't set the server.port property to 80 as mentioned in the example (we will be fixing the example very soon).

Upvotes: 0

Aditya T
Aditya T

Reputation: 1723

I can guess from given info that docker commands are not correct with respect to networking.

First create a docker network using

docker network create your_network_name

Then connect both applications to same network using

--network your_network_name

No need to expose any ports outside if not needed externally, also once the applications are up, use following command to check if both shows up in network you created

docker network your_network_name inspect

If you're unable to figure out what I am saying at the moment, let me know, I will update answer accordingly.

Upvotes: 1

Related Questions