Azure Web App multi-conainter

ȘTEFAN BUCIU 21 Reputation points
2021-04-09T19:32:30.39+00:00

After following multiple tutorials and guides from the official docs, I started to configure a web app with a custom docker-compose file.

I have two containers: a spring boot API and a MySQL image. This is the docker-compose file that I'm using:

version: '3.8'  
services:  
  mysql:  
    image: mysql:8  
    restart: always  
    environment:  
      - MYSQL_ROOT_PASSWORD=1234  
      - MYSQL_USER=admindev  
      - MYSQL_PASSWORD=admindev  
      - MYSQL_DATABASE=admindevdb  
  
  myapi:  
    image: <my_user>.azurecr.io/<my_image>  
    restart: always  
    ports:  
      # Azure Web App exposes port 80  
      - 80:5000  
    depends_on:  
      - mysql  
    environment:  
      - SERVER_PORT=5000  
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/admindevdb  
      - SPRING_DATASOURCE_USERNAME=admindev  
      - SPRING_DATASOURCE_PASSWORD=admindev  
      - SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.mysql.cj.jdbc.Driver  
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update  
      - SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.MySQL5InnoDBDialect  

Locally when I run this docker-compose it works flawlessly. My app starts and I can make requests to my api.

When I'm using an app service, there is another story.

So the first step, the engine downloads the images. That goes well.
Then, it starts both images. Even though I have a depends_on property in myapi on the mysql service, the containers start simultaneously. This generates some error in my app because the MySQL service is not ready yet. After a little while, I get informed in the logs that the MySQL is ready. When that's the case, the app also tells me that it started. But right after that, for some odd reason, the app service decides to restart the containers. And this cycle goes on and on and on.

I suspect that the app service decides to restart the containers because my app is failing at some point. But if the last thing that it does, is running successfully should it not restart it? Here are some logs:

2021-04-09T19:16:59.551986327Z 2021-04-09 19:16:59.551 INFO 1 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!  
2021-04-09T19:16:59.648270526Z 2021-04-09 19:16:59.631 INFO 1 --- [ main] hello.world.MyApp : Started MyApp in 82.175 seconds (JVM running for 99.723)  
  
2021-04-09T19:17:22.858Z INFO - Stopping site <site> because it failed during startup.  

What can I do in this case? Also, how is this debuggable? Locally it works, if I run the apps locally in docker they also work, only in the App Service they fail. Do you have any advice?

Also, I opened a question on SO, if you want to have a look there as well, you can click here.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,114 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 26,546 Reputation points Microsoft Employee
    2021-04-11T01:12:21.73+00:00

    Hi @ȘTEFAN BUCIU ,

    Mutli container app is still a preview feature so there are many features that don't work. depends_on is one of those commands that gets ignored; see Docker Compose options under Configure multi-container apps for a complete list of supported and unsupported docker commands. There aren't any details I can share at the moment with regards to general availability or when/if depends_on gets supported.

    I advise reconfiguring your API app so that the mysql isn't a dependency on application start up. If upon reconfiguring your app and you still experience issues with container startup, please comment down below.

    Regards,
    Ryan

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful