title: Start mysql automatically when running a Docker container
body: <p>I have created a Dockerfile to have a development environment on my computer with php7, mysql and some other library.</p>
  
  <p>The apache service starts automatically when a run the container but I can't get the same results with mysql. The last sentence of my Dockerfile looks like this <code>CMD ["bash", "run.sh"]</code> and then in <em>run.sh</em> I have this:</p>
  
  <pre><code>#!/bin/bash
  set -e
  
  PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL"}
  sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php/7.0/apache2/php.ini
  sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php/7.0/cli/php.ini
  sed -ri "s/^error_reporting\s*=.*$//g" /etc/php/7.0/apache2/php.ini
  sed -ri "s/^error_reporting\s*=.*$//g" /etc/php/7.0/cli/php.ini
  echo "error_reporting = $PHP_ERROR_REPORTING" &gt;&gt; /etc/php/7.0/apache2/php.ini
  echo "error_reporting = $PHP_ERROR_REPORTING" &gt;&gt; /etc/php/7.0/cli/php.ini
  
  source /etc/apache2/envvars &amp;&amp; exec /usr/sbin/apache2 -DFOREGROUND
  
  chmod 0755 start.sh
  sleep 1
  start.sh
  
  /bin/bash
  </code></pre>
  
  <p>That calls a file named <em>start.sh</em> that looks like this:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  # Mysql
  sed -i -e 's/127.0.0.1/0.0.0.0/g' /etc/mysql/mysql.conf.d/mysqld.cnf
  service mysql start
  </code></pre>
  
  <p>It is divided in two files because I tested everything but I can't get it working. If I do a docker exec inside the container and I start mysql everything works fine.</p>
  
  <p>Any idea of what I am doing wrong?</p>