title: Best way to initialize DB script while building docker image
body: <p>I am building a docker machine using the image "mysql". I have some setup script to run for the first time the machine is built. This setup script will create some database and dabase users with specified permmissions.</p>
  
  <p><strong>Following are the minimized version of my files..</strong></p>
  
  <p><em>pcdb1.entrypoint.sh</em></p>
  
  <pre><code>#!/bin/sh
  
  mysql -uroot -p'pass123' -e 'show databases MYENTRYDB;'
  </code></pre>
  
  <p><em>Dockerfile</em></p>
  
  <pre><code>FROM mysql:5.7
  
  COPY ./pcdb1.entrypoint.sh /
  ENTRYPOINT ["/pcdb1.entrypoint.sh"];
  </code></pre>
  
  <p>I am getting the following error in the log</p>
  
  <blockquote>
    <p>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) </p>
    
    <p>pcdb1 exited with code 1</p>
  </blockquote>
  
  <p>What I understood is, my script is trying to run before mysql is started. But I am not sure how to do it properly. Can I get a suggestion?</p>