Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose health check passed, still unhealthy #9367

Closed
sshallow opened this issue Apr 8, 2022 · 2 comments
Closed

docker-compose health check passed, still unhealthy #9367

sshallow opened this issue Apr 8, 2022 · 2 comments

Comments

@sshallow
Copy link

sshallow commented Apr 8, 2022

condition 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 condition as an option in long syntax form of depends_on.

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 healthcheck

But there is a problem with the healthcheck of mysql, this is my docker-compose

# docker-compose.yml
version: "3.9"  

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:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: fuba-db
      MYSQL_ROOT_PASSWORD: fb123456
    healthcheck:
      test: "mysql -uroot -p$$MYSQL_ROOT_PASSWORD  -e 'SELECT * FROM factor_header' fuba-db "
      interval: 1s
      timeout: 3s
      retries: 3

  redis:
    build:
      ......

  nginx:
    build:
      ......

  fubaquant:
    build:
      context: ./webapps
    ports:
      - "8080:8080"
    volumes:
      - /mnt/java/jar:/home/ruoyi  #jar包
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started

The statement in error is:

test: "mysql -uroot -p$$MYSQL_ROOT_PASSWORD  -e 'SELECT * FROM factor_header' fuba-db "

The console outputs :

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 "mysql" is unhealthy

Since fubaquant depends_on mysql healthcheck, fubaquant is not started either

The health check log of the mysql container is:

docker-compose up

I checked th healthcheck log of mysql and it's also healthy

mysql  log

thanks for any help

@ndeloof
Copy link
Contributor

ndeloof commented Apr 8, 2022

You configured health check to only allow 3 retries, 1 second intervals. While compose is starting your app, mysql service has not reached the healthy state within this 3s delay, so compose stops and report this error. Try to increase this delay or number of retries.

@sshallow
Copy link
Author

sshallow commented Apr 8, 2022

@ndeloof Thanks !!! I increased the number of retries and it's work!
I'm so stupid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants