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.