title: composer install fails when unable to see mysql database
body: <p><strong>TL;DR: composer install fails when the post-install scripts can't see a MySQL server</strong></p>
  
  <p>I'm building a docker container for a Symfony application, and during the build I do something like this</p>
  
  <pre><code>RUN export SYMFONY_ENV=prod &amp;&amp; \
    composer install --prefer-dist --optimize-autoloader
  </code></pre>
  
  <p>Towards the end of the install, it fails with this</p>
  
  <pre><code>Generating optimized autoload files
  
  
    [Doctrine\DBAL\Exception\DriverException]                                                                  
    An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  
  
    [Doctrine\DBAL\Driver\PDOException]                                        
    SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  
  
    [PDOException]                                                             
    SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  
  
  
  Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
  
    [RuntimeException]                                                         
    An error occurred when executing the "'cache:clear --no-warmup'" command.  
  </code></pre>
  
  <p>Now, I could use <code>--no-scripts</code> but then presumably I'd need to run <code>composer install</code> again after starting a container, and I'd like my container to be as ready as possible.</p>
  
  <p>As I've not found many references to similar problems, there might be something in my application at fault, and I suspect I'll be answering my own question. My hope was that in describing it, I would figure it out. Alas, I haven't. Clues are welcome :)</p>