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 :/
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
healthcheck.sh is like:
#!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
mysql container Dockerfile:
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
docker-compose.yml like:
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
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?
Thx Markus
 
     
     
    