title: Adding Flyway to a MySQL Docker Container
body: <p>I'm building an derivative to this Docker container for mysql (using it as a starting point): <a href="https://github.com/docker-library/mysql" rel="noreferrer">https://github.com/docker-library/mysql</a></p>
  
  <p>I've amended the Dockerfile to add in Flyway. Everything is set up to edit the config file to connect to the local DB instance, etc. The intent is to call this command from inside the <code>https://github.com/docker-library/mysql/blob/master/5.7/docker-entrypoint.sh</code> file (which runs as the ENTRYPOINT) around line 186:</p>
  
  <pre><code>flyway migrate
  </code></pre>
  
  <p>I get a connection refused when this is run from inside the shell script: </p>
  
  <pre><code>Flyway 4.1.2 by Boxfuse
  
  ERROR: 
  Unable to obtain Jdbc connection from DataSource 
  (jdbc:mysql://localhost:3306/db-name) for user 'root': Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused
  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SQL State  : 08
  Error Code : -1
  Message    : Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused
  </code></pre>
  
  <p>But, if I remove the command from the shell script, rebuild and log in to the container, and run the same command manually, it works with no problems.</p>
  
  <p>I suspect that there may be some differences with how the script connects to the DB to do its thing (it has a built in SQL "runner"), but I can't seem to hunt it down. The container restarts the server during the process, which is what may be the difference here.</p>
  
  <p>Since this container is intended for development, one alternative (a work-around, really) is to use the built in SQL "runner" for this container, using the filename format that Flyway expects, then use Flyway to manage the production DB's versions.</p>
  
  <p>Thanks in advance for any help.</p>