Heim  >  Fragen und Antworten  >  Hauptteil

Die Gesundheitsprüfung von Docker-Compose ist erfolgreich, aber immer noch fehlerhaft

condition 在版本 3.0 至 3.8 中已删除 compose 规范,但现在又回来了!使用 compose 规范 v3.9 版本,您可以使用 condition 作为 depends_on Optionen in langer Syntaxform.

Ich verwende Docker Compose, um MySQL- und Java-Webprojekte zu starten. Der Start von JavaWeb erfordert, dass MySQL vollständige Daten erstellt, daher verwende ich Healthcheck

Aber MySQL healthcheck有问题,这是我的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

Die falsche Aussage ist:

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

Konsolenausgabe:

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

Aufgrund von Fubaquant-Abhängigkeiten_auf MySQL-Gesundheitscheck wird Fubaquant auch nicht gestartet

Das Gesundheitsprüfprotokoll des MySQL-Containers lautet:

Ich habe das Health-Check-Protokoll von MySQL überprüft und es ist auch fehlerfrei

Vielen Dank für Ihre Hilfe

P粉596161915P粉596161915236 Tage vor345

Antworte allen(2)Ich werde antworten

  • P粉316890884

    P粉3168908842024-02-27 00:28:40

    您似乎正在尝试使用错误的用户和密码运行运行状况检查。你有

    healthcheck:
          test: ["CMD", "mysqladmin", "-u$mysql", "-p$123456",  "ping", "-h", "localhost"]
    

    $mysql$123456 将尝试解析这些变量的值。您想要的是使用以下内容。

    healthcheck:
          test: ["CMD", "mysqladmin", "-u$MYSQL_USER", "-p$MYSQL_PASSWORD",  "ping", "-h", "localhost"]
    

    然后,这将尝试使用用户 mysql 和密码 123456 运行 mysaqladmin (两者都定义为 docker-compose 上 mysql 服务的环境变量)

    Antwort
    0
  • P粉022140576

    P粉0221405762024-02-27 00:26:56

    我将运行状况检查配置为仅允许 3 次重试,间隔 1 秒。当 compose 启动 java 时,mysql 服务在这 3 秒的延迟内尚未达到健康状态,因此 compose 停止并报告此错误。 增加重试次数后就可以了

    Antwort
    0
  • StornierenAntwort