Q:

MySQL - Docker Image : How to wait till the tables are populated before starting the next container

I'm trying to start a Docker container of a server which uses MySQL as it's database. In order to start this server I want the MySQL tables to be created first,otherwise the server exits giving an error. I want my second container to wait until the MySQL docker image finish creating tables.
I cannot handle this from server side as it is not a product that I own. I am using Docker-compose version 3 and use wait-for-it.sh to wait till the MySQL container is started before starting the server container. Also I have added my SQL scripts into "/docker-entrypoint-initdb.d" so that the tables will be created at the startup.But, wait-for-it.sh only wait until the MySQL server is ready to start communicating,not until all the tables are created(MySQL server is idle). So when i start the containers for the first time, my server exits with error code as the tables are not created yet. 
version: '3.7'
services:

  mysql:
    container_name: mysql
    image: mysql:5.7.24
    ports:
      - "3306"
    volumes:
      - "./mysql/scripts:/docker-entrypoint-initdb.d"
    command: [--ssl=0]
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-uroot", "-proot"]
      interval: 10s
      timeout: 10s
      retries: 5
      start_period: 30s

  server:
    container_name: server
    image: server
    depends_on:
      - "mysql"
    volumes:
      - "./wait-for-it.sh:/home/wait-for-it.sh"
    entrypoint:
      - "/home/wait-for-it.sh"
      - "mysql:3306"
      - "-t"
      - "30"
      - "--"
      - "./docker-entrypoint.sh"

I don't want to increase the startup time of the second container as this happens only at the first time I initialize the container. After the first time as the tables are already created this doesn't become and issue and if I increase the startup time of the second container, the user will have to face an unnecessary delay.

A:

You are getting the concept of wait-for-it wrong. It will not work they way you are expecting.
It will not wait to populate your whole DB, it just waits for availability of a host and TCP port, if the wait-for-it able to create connection then it will mark the container ready.
You can handle such logic on your application side.

wait-for-it.sh is a pure bash script that will wait on the
  availability of a host and TCP port. It is useful for synchronizing
  the spin-up of interdependent services, such as linked docker
  containers. Since it is a pure bash script, it does not have any
  external dependencies.

Other option you can try
You can set your own timeout with the -t or --timeout= option. Setting the timeout value to 0 will disable the timeout:

