mysql.dockerfile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ENV MYSQL_VERSION 8.0.21-1ubuntu18.04
  14. # https://bugs.mysql.com/bug.php?id=90695
  15. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-server mysql-server/lowercase-table-names select Enabled\""]
  16. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/data-dir select 'Y'\""]
  17. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/root-pass password secret\""]
  18. RUN ["/bin/bash", "-c", "debconf-set-selections <<< \"mysql-community-server mysql-community-server/re-root-pass password secret\""]
  19. RUN DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server="${MYSQL_VERSION}" > /dev/null
  20. RUN mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  21. RUN cp my.cnf /etc/mysql/my.cnf
  22. RUN rm -rf /ssd/mysql
  23. RUN rm -rf /ssd/log/mysql
  24. RUN cp -R -p /var/lib/mysql /ssd/
  25. RUN cp -R -p /var/log/mysql /ssd/log
  26. RUN mkdir -p /var/run/mysqld
  27. # It may seem weird that we call `service mysql start` several times, but the RUN
  28. # directive is a 1-time operation for building this image. Subsequent RUN calls
  29. # do not see running processes from prior RUN calls; therefor, each command here
  30. # that relies on the mysql server running will explicitly start the server and
  31. # perform the work required.
  32. RUN chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && \
  33. mysqld & \
  34. until mysql -uroot -psecret -e "exit"; do sleep 1; done && \
  35. mysqladmin -uroot -psecret flush-hosts && \
  36. mysql -uroot -psecret < create.sql
  37. CMD chown -R mysql:mysql /var/lib/mysql /var/log/mysql /var/run/mysqld /ssd && mysqld