title: Docker healthcheck in composer file
body: <p>I try to integrate the new healthcheck into my docker system, but I don't really know how to do it in the right way :/</p>
  
  <p>The problem is, my database container needs more time to start up and initialize the database then the container who starts my main application.
  As a result: the main container wont start correct, cause of the missing database connection.
  I wrote an healthcheck.sh script to check the database container for connectivity, so the main container starts booting after the connectivity is available. But I dont know how to integrate it correctly in the Dockerfile and my docker-compose.yml</p>
  
  <p>healthcheck.sh is like:</p>
  
  <pre><code>#!bin/bash
  COUNTER=0
  while [[ $COUNTER = 0 ]]; do
    mysql --host=HOST --user="user" --password="password" --database="databasename" --execute="SELECT 1";
    if [[ $? == 1 ]]; then
      sleep 1
      echo "Let's sleep again"
    else
      COUNTER=1
      echo "OK, lets go!"
    fi
  done
  </code></pre>
  
  <p>mysql container Dockerfile:</p>
  
  <pre><code>FROM repository/mysql-5.6:latest
  MAINTAINER Me
  
  ... some copies, chmod and so on 
  
  VOLUME ["/..."]
  
  EXPOSE 3306
  
  CMD [".../run.sh"]
  
  HEALTHCHECK --interval=1s --timeout=3s CMD ./healthcheck.sh
  </code></pre>
  
  <p>docker-compose.yml like:</p>
  
  <pre><code>version: '2'
  services:
    db:
      image: db image
      restart: always
      dns:
        - 10.
      ports:
        - "${MYSQL_EXTERNAL_PORT}:${MYSQL_INTERNAL_PORT}"
      environment:
        TZ: Europe/Berlin
    data:
      image: data image
  
    main application:
      image: application image
      restart: always
      dns:
        - 10.
      ports:
        - "${..._EXTERNAL_PORT}:${..._INTERNAL_PORT}"
      environment:
        TZ: Europe/Berlin
      volumes:
        - ${HOST_BACKUP_DIR}:/...
      volumes_from:
        - data
        - db
  </code></pre>
  
  <p>What do I have to do to integrate this healthcheck into my docker-compose.yml file to work?
  Or is there any other chance to delay the container startup of my main container?</p>
  
  <p>Thx Markus</p>