title: Docker : Start mysql and apache from entrypoint or CMD
body: <p>Building a docker image for development, I want to start automatically mysql and apache when I run the image.</p>
  
  <p>If I log into the container and run "service apache2 start" and "service mysql start" it works. But if I put in entrypoint or CMD it fails.
  I was able to start apache by putting  <code>ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]</code>but I was not able to start mysql programmatically.</p>
  
  <p>I tried many many things. Most of the time if fails silently in that the container is not running, other time I got : docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/etc/init.d/mysql start\": stat /etc/init.d/mysql start: no such file or directory"</p>
  
  <p>This is what I have so far :</p>
  
  <pre><code>FROM debian:wheezy
  
  RUN apt-get update &amp;&amp; \
      apt-get install -y libmcrypt-dev \
      subversion ssl-cert nano wget unzip &amp;&amp; \
      echo "deb http://packages.dotdeb.org wheezy-php56 all" &gt;&gt; /etc/apt/sources.list.d/dotdeb.list &amp;&amp; \
      echo "deb-src http://packages.dotdeb.org wheezy-php56 all" &gt;&gt; /etc/apt/sources.list.d/dotdeb.list &amp;&amp; \
      wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - &amp;&amp; \
      echo mysql-server-5.5 mysql-server/root_password password yourpass | debconf-set-selections &amp;&amp; \
      echo mysql-server-5.5 mysql-server/root_password_again password yourpass | debconf-set-selections &amp;&amp; \
      apt-get update &amp;&amp; \
      apt-get install -y \
      apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 \
      openssl php-pear php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-memcache php5-readline \
      subversion ssl-cert nano wget unzip \
      mysql-server-5.5 mysql-client mysql-client-5.5 mysql-common &amp;&amp; \
      /etc/init.d/mysql start &amp;&amp; \
      mysql -u root -pyourpass -e "create database mydb;" &amp;&amp; \
      rm -rf /var/lib/apt/lists/* &amp;&amp; \
      rm /etc/apache2/sites-enabled/000-default &amp;&amp; \
      mkdir -p /var/www/html &amp;&amp; \
      chown www-data:www-data -R /var/www/html/
  
  COPY conf/etc/ /etc/
  COPY mydump.sql /var/www/html/mydump.sql
  
  RUN /etc/init.d/mysql start &amp;&amp; \
      mysql -u root -pyourpass -h localhost mydb &lt; /var/www/html/mydump.sql &amp;&amp; \
      rm /var/www/html/mydump.sql
  
  VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2", "/var/lib/mysql"]
  
  EXPOSE 80 443 3306
  </code></pre>