How to view docker-compose healthcheck logs?

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

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

This healthcheck does not work, shows that the service is unhealthy.

  • Gitlab pipeline fails during connect with EOF
  • Docker: listening in container, not answering outside
  • Shiny server inside Docker container reverse proxied with nginx will not follow 301 redirects
  • Enabling Remote API in Docker on Mac OS X (boot2docker)
  • Putting a uWSGI fast router in front of uWSGI servers running in docker containers
  • Postgresql and Docker
  • How do I check the output of the test CMD?

  • Mapping docker port is failed
  • CF Garden-runC as a container orchestration engine?
  • Command nesting in VSTS/TFS
  • Unable to set up Docker UCP cluster
  • How do I get an exit code from an Amazon ECS Task?
  • Run Different Linux OS in Docker Container?
  • One Solution collect form web for “How to view docker-compose healthcheck logs?”

    You can use :

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


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

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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.