How to view waiter logs?

Inside my docker-compose.yml , I have the following service healthcheck section. I want to know if MariaDB is ready to handle requests. A service named cmd configured to depend on condition: service_healthy .

  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 

This health check does not work, indicates that the service is unhealthy.

How to check test CMD output?

+6
source share
1 answer

You can use:

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

Output:

 { "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" 

And find the output section.

To get only output:

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

Feel free to change jq for any tool you use for json pretty print.

+14
source

Source: https://habr.com/ru/post/1015680/


All Articles