LMSouq
server-admin Open

Docker-compose check if mysql connection is ready

JO
John Kariuki
1 month ago
3 views
Problem Description
I am trying to make sure that my app container does not run migrations / start until the db container is started and READY TO accept connections. So I decided to use the healthcheck and depends on option in docker compose file v2. In the app, I have the following app: ... depends_on: db: condition: service_healthy The db on the other hand has the following healthcheck db: ... healthcheck: test: TEST_GOES_HERE timeout: 20s retries: 10 I have tried a couple of approaches like : 1. making sure the db DIR is created ``` test: ["CMD", "test -f var/lib/mysql/db"] ``` 2. Getting the mysql version: ``` test: ["CMD", "echo 'SELECT version();'| mysql"] ``` 3. Ping the admin (marks the db container as healthy but does not seem to be a valid test) ``` test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] ``` Does anyone have a solution to this?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base