title: Creating mysql dockerfile from previous docker-compose set-up
body: <p>Previously, my database container was initialized with docker-compose.
  Since I'm moving to AWS, I want to place it in a Dockerfile. This is apparently not as straightforward as I thought. How can I do this?</p>
  
  <p><strong>Docker-compose</strong></p>
  
  <pre><code>services:
    mysql-db:
      image: mysql:latest
      container_name: camunda_mysql
      restart: always
      ports:
        - '3307:3306'
      environment: 
        - MYSQL_ROOT_PASSWORD=***
        - MYSQL_USER=***
        - MYSQL_DATABASE=camunda_db
      volumes:
        - MyDataVolume:/var/lib/mysql
      networks:
        - backend
  volumes:
    MyDataVolume:
  </code></pre>
  
  <p>This is something I found online, but I can't get it to work:</p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM ubuntu:latest
  RUN dpkg-divert --local --rename --add /sbin/initctl
  RUN ln -s /bin/true /sbin/initctl
  RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" &gt; /etc/apt/sources.list
  RUN apt-get update
  RUN apt-get -y install mysql-client mysql-server
  RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
  ADD ./startup.sh /opt/startup.sh
  EXPOSE 3306
  CMD ["/bin/bash", "/opt/startup.sh"]
  </code></pre>
  
  <p><strong>startup.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  
  if [ ! -f /var/lib/mysql/ibdata1 ]; then
      mysql_install_db
  
      /usr/bin/mysqld_safe &amp;
      sleep 10s
  
      echo "GRANT ALL ON *.* TO USERNAME@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql
  
      killall mysqld
      sleep 10s
  fi
  
  /usr/bin/mysqld_safe
  </code></pre>
  
  <p>Thank you!</p>