title: Docker-compose check if mysql connection is ready
body: <p>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.</p>
  
  <p>So I decided to use the healthcheck and depends on option in docker compose file v2.</p>
  
  <p>In  the app, I have the following </p>
  
  <pre><code>app:
      ...
      depends_on:
        db:
        condition: service_healthy
  </code></pre>
  
  <p>The db on the other hand has the following healthcheck</p>
  
  <pre><code>db:
    ...
    healthcheck:
      test: TEST_GOES_HERE
      timeout: 20s
      retries: 10
  </code></pre>
  
  <p>I have tried a couple of approaches like :</p>
  
  <ol>
  <li>making sure the db DIR is created
  <code>
  test: ["CMD", "test -f var/lib/mysql/db"]
  </code></li>
  <li>Getting the mysql version:
  <code>
  test: ["CMD", "echo 'SELECT version();'| mysql"]
  </code></li>
  <li>Ping the admin (marks the db container as healthy but does not seem to be a valid test)
  <code>
  test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
  </code></li>
  </ol>
  
  <p>Does anyone have a solution to this?</p>