How to view docker-compose healthcheck logs?

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 look for the output section.

To get the Output only:

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

For swarm mode use the folling format (thanks for pointing it out @shotgunner):

{{json.Spec.TaskTemplate.ContainerSpec.Healthcheck}}

Feel free to swap jq for whatever tool you use for json pretty print.

Leave a Comment