2017-03-11 10 views
5

À l'intérieur de mon docker-compose.yml, j'ai la section suivante servicehealthcheck. Je veux savoir si MariaDB est réellement prête à gérer les requêtes. Un service nommé cmd est configuré pour dépendre de condition: service_healthy.Comment afficher les journaux healthcheck de docker-composer?

db: 
    image: mariadb:10 
    environment: 
     MYSQL_RANDOM_ROOT_PASSWORD: 1 
     MYSQL_USER: user 
     MYSQL_PASSWORD: password 
     MYSQL_DATABASE: database 
    healthcheck: 
     test: ["CMD", "mysql", "--user=user", "--password=password", "--execute='SELECT 1'", "--host=127.0.0.1", "--port=3306"] 
     interval: 1s 
     retries: 30 

Ce healthcheck ne fonctionne pas, montre que le service est malsain.

Comment vérifier la sortie du CMD test?

Répondre

13

Vous pouvez utiliser:

docker inspect --format "{{json .State.Health }}" <container name> | jq 

Sortie:

{ 
    "Status": "unhealthy", 
    "FailingStreak": 63, 
    "Log": [ 
    { 
     "Start": "2017-03-11T20:49:19.668895201+03:30", 
     "End": "2017-03-11T20:49:19.735722044+03:30", 
     "ExitCode": 1, 
     "Output": "ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''SELECT 1'' at line 1\n" 

Et chercher la sortie section.

Pour obtenir la sortie seulement:

docker inspect --format "{{json .State.Health }}" mariadb_db_1 | jq '.Log[].Output' 

Ne hésitez pas à échanger jq pour quelque outil que vous utilisez pour JSON assez d'impression.