I'm working on a project that requires an external MySQL database, but I'm not sure how to set this up with Docker Compose. From what I understand, the `depends_on` directive only works for services defined within the Compose file. Is there a way to achieve this with an external MySQL instance? I've come across some older discussions but haven't found a practical solution yet.
2 Answers
The most reliable method is to put a database connection check in your application’s entrypoint command. This way, your app won't start until the database is reachable. It adds some robustness to your deployment!
One approach you could try is using a health check. You can set up a health check to ensure that the MySQL database is ready before your application starts. Check out the Docker documentation for more details on how to implement this!
Do you know how to implement that in detail?