mysql.dockerfile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. FROM buildpack-deps:bionic
  2. ADD create.sql create.sql
  3. ADD my.cnf my.cnf
  4. ADD mysql.list mysql.list
  5. RUN cp mysql.list /etc/apt/sources.list.d/
  6. RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8C718D3B5072E1F5
  7. RUN apt-get update > /dev/null
  8. RUN apt-get install -yqq locales > /dev/null
  9. RUN locale-gen en_US.UTF-8
  10. ENV LANG en_US.UTF-8
  11. ENV LANGUAGE en_US:en
  12. ENV LC_ALL en_US.UTF-8
  13. # https://bugs.mysql.com/bug.php?id=90695
  14. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-server mysql-server/lowercase-table-names select Enabled\""]
  15. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/data-dir select 'Y'\""]
  16. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/root-pass password secret\""]
  17. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/re-root-pass password secret\""]
  18. RUN DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server > /dev/null
  19. RUN mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  20. RUN cp my.cnf /etc/mysql/my.cnf
  21. RUN rm -rf /ssd/mysql
  22. RUN rm -rf /ssd/log/mysql
  23. RUN cp -R -p /var/lib/mysql /ssd/
  24. RUN cp -R -p /var/log/mysql /ssd/log
  25. # It may seem weird that we call `service mysql start` several times, but the RUN
  26. # directive is a 1-time operation for building this image. Subsequent RUN calls
  27. # do not see running processes from prior RUN calls; therefor, each command here
  28. # that relies on the mysql server running will explicitly start the server and
  29. # perform the work required.
  30. RUN chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && \
  31. mysqld & \
  32. until mysql -uroot -psecret -e "exit"; do sleep 1; done && \
  33. mysqladmin -uroot -psecret flush-hosts && \
  34. mysql -uroot -psecret < create.sql
  35. CMD chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && mysqld