title: docker-compose health check passed, still unhealthy
body: <blockquote>
  <p><em><code>condition</code> was removed compose spec in versions 3.0 to 3.8 but is now back!  Using version of the compose spec v3.9, you can use <code>condition</code> as an option in <a href="https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1" rel="nofollow noreferrer">long syntax form of <code>depends_on</code></a>.</em></p>
  </blockquote>
  <p>I use docker compose to start MySQL and Java Web projects,
  The startup of JavaWeb needs to rely on MySQL to create complete data, so I use <a href="https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1" rel="nofollow noreferrer">healthcheck</a></p>
  <p>But there is a problem with the <code> healthcheck</code> of mysql, this is my <code>docker-compose</code></p>
  <pre><code># docker-compose.yml
  version: &quot;3.9&quot;  
  
  services:
  
    mysql:
      build:
        context: ./mysql
      command: [
          'mysqld',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
      ]
      ports:
        - &quot;3306:3306&quot;
      environment:
        MYSQL_DATABASE: fuba-db
        MYSQL_ROOT_PASSWORD: fb123456
      healthcheck:
        test: &quot;mysql -uroot -p$$MYSQL_ROOT_PASSWORD  -e 'SELECT * FROM factor_header' fuba-db &quot;
        interval: 1s
        timeout: 3s
        retries: 3
  
    redis:
      build:
        ......
  
    nginx:
      build:
        ......
  
    fubaquant:
      build:
        context: ./webapps
      ports:
        - &quot;8080:8080&quot;
      volumes:
        - /mnt/java/jar:/home/ruoyi  #jar包
      depends_on:
        mysql:
          condition: service_healthy
        redis:
          condition: service_started
  </code></pre>
  <p>The statement in error is:</p>
  <pre><code>test: &quot;mysql -uroot -p$$MYSQL_ROOT_PASSWORD  -e 'SELECT * FROM factor_header' fuba-db &quot;
  </code></pre>
  <p>The console outputs :</p>
  <pre><code>pro-mysql-1      | 2022-04-07T08:16:54.203710Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  container for service &quot;mysql&quot; is unhealthy
  </code></pre>
  <p><em>Since fubaquant depends_on mysql healthcheck, fubaquant is not started either</em></p>
  <p>The health check log of the mysql container is:</p>
  <p><a href="https://i.stack.imgur.com/DXrwH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DXrwH.jpg" alt="docker-compose up" /></a></p>
  <p>I checked th healthcheck log of mysql and it's also healthy</p>
  <p><a href="https://i.stack.imgur.com/MDxEm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDxEm.jpg" alt="mysql  log" /></a></p>
  <p>thanks for any help</p>