title: How do I know when my docker mysql container is up and mysql is ready for taking queries?
body: <p>I am deploying a few different docker containers, mysql being the first one. I want to run scripts as soon as database is up and proceed to building other containers. The script has been failing because it was trying to run when the entrypoint script, which sets up mysql (from <a href="https://registry.hub.docker.com/_/mysql/" rel="noreferrer">this official mysql container</a>), was still running.</p>
  
  <pre><code>sudo docker run --name mysql -e MYSQL_ROOT_PASSWORD=MY_ROOT_PASS -p 3306:3306 -d mysql
  [..] wait for mysql to be ready [..]
  mysql -h 127.0.0.1 -P 3306 -u root --password=MY_ROOT_PASS &lt; MY_SQL_SCRIPT.sql
  </code></pre>
  
  <p>Is there a way to wait for a signal of an entrypoiny mysql setup script finishing inside the docker container? Bash sleep seems like a suboptimal solution.</p>
  
  <p>EDIT: Went for a bash script like this. Not the most elegant and kinda brute force but works like a charm. Maybe someone will find that useful.</p>
  
  <pre><code>OUTPUT="Can't connect"
  while [[ $OUTPUT == *"Can't connect"* ]]
  do
      OUTPUT=$(mysql -h $APP_IP -P :$APP_PORT -u yyy --password=xxx &lt;       ./my_script.sql 2&gt;&amp;1)
  done
  </code></pre>