|
| 1 | +FROM debian:{{ .debian.suite }}-slim |
| 2 | + |
| 3 | +# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added |
| 4 | +RUN groupadd -r mysql && useradd -r -g mysql mysql |
| 5 | + |
| 6 | +RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr && rm -rf /var/lib/apt/lists/* |
| 7 | + |
| 8 | +# add gosu for easy step-down from root |
| 9 | +# https://github.com/tianon/gosu/releases |
| 10 | +ENV GOSU_VERSION 1.12 |
| 11 | +RUN set -eux; \ |
| 12 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 13 | + apt-get update; \ |
| 14 | + apt-get install -y --no-install-recommends ca-certificates wget; \ |
| 15 | + rm -rf /var/lib/apt/lists/*; \ |
| 16 | + dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ |
| 17 | + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ |
| 18 | + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ |
| 19 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 20 | + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ |
| 21 | + gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ |
| 22 | + gpgconf --kill all; \ |
| 23 | + rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ |
| 24 | + apt-mark auto '.*' > /dev/null; \ |
| 25 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ |
| 26 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 27 | + chmod +x /usr/local/bin/gosu; \ |
| 28 | + gosu --version; \ |
| 29 | + gosu nobody true |
| 30 | + |
| 31 | +RUN mkdir /docker-entrypoint-initdb.d |
| 32 | + |
| 33 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 34 | +# for MYSQL_RANDOM_ROOT_PASSWORD |
| 35 | + pwgen \ |
| 36 | +{{ |
| 37 | + if env.version != "5.6" then ( |
| 38 | +-}} |
| 39 | +# for mysql_ssl_rsa_setup |
| 40 | + openssl \ |
| 41 | +{{ ) else "" end -}} |
| 42 | +# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db: |
| 43 | +# File::Basename |
| 44 | +# File::Copy |
| 45 | +# Sys::Hostname |
| 46 | +# Data::Dumper |
| 47 | + perl \ |
| 48 | +# install "xz-utils" for .sql.xz docker-entrypoint-initdb.d files |
| 49 | + xz-utils \ |
| 50 | + && rm -rf /var/lib/apt/lists/* |
| 51 | + |
| 52 | +RUN set -ex; \ |
| 53 | +# gpg: key 5072E1F5: public key "MySQL Release Engineering < [email protected]>" imported |
| 54 | + key='A4A9406876FCBD3C456770C88C718D3B5072E1F5'; \ |
| 55 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 56 | + gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ |
| 57 | + gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; \ |
| 58 | + gpgconf --kill all; \ |
| 59 | + rm -rf "$GNUPGHOME"; \ |
| 60 | + apt-key list > /dev/null |
| 61 | + |
| 62 | +ENV MYSQL_MAJOR {{ env.version }} |
| 63 | +ENV MYSQL_VERSION {{ .debian.version }} |
| 64 | + |
| 65 | +RUN echo 'deb http://repo.mysql.com/apt/debian/ {{ .debian.suite }} mysql-{{ env.version }}' > /etc/apt/sources.list.d/mysql.list |
| 66 | + |
| 67 | +# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql) |
| 68 | +# also, we set debconf keys to make APT a little quieter |
| 69 | +RUN { \ |
| 70 | + echo mysql-community-server mysql-community-server/data-dir select ''; \ |
| 71 | + echo mysql-community-server mysql-community-server/root-pass password ''; \ |
| 72 | + echo mysql-community-server mysql-community-server/re-root-pass password ''; \ |
| 73 | + echo mysql-community-server mysql-community-server/remove-test-db select false; \ |
| 74 | + } | debconf-set-selections \ |
| 75 | + && apt-get update \ |
| 76 | + && apt-get install -y \ |
| 77 | +{{ if env.version == "5.6" or env.version == "5.7" then ( -}} |
| 78 | + mysql-server="${MYSQL_VERSION}" \ |
| 79 | +# comment out a few problematic configuration values |
| 80 | + && find /etc/mysql/ -name '*.cnf' -print0 \ |
| 81 | + | xargs -0 grep -lZE '^(bind-address|log)' \ |
| 82 | + | xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/' \ |
| 83 | +# don't reverse lookup hostnames, they are usually another container |
| 84 | + && echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf \ |
| 85 | +{{ ) else ( -}} |
| 86 | + mysql-community-client="${MYSQL_VERSION}" \ |
| 87 | + mysql-community-server-core="${MYSQL_VERSION}" \ |
| 88 | +{{ ) end -}} |
| 89 | + && rm -rf /var/lib/apt/lists/* \ |
| 90 | + && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \ |
| 91 | + && chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \ |
| 92 | +# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime |
| 93 | + && chmod 1777 /var/run/mysqld /var/lib/mysql |
| 94 | + |
| 95 | +VOLUME /var/lib/mysql |
| 96 | + |
| 97 | +{{ if env.version != "5.6" and env.version != "5.7" then ( -}} |
| 98 | +# Config files |
| 99 | +COPY config/ /etc/mysql/ |
| 100 | +{{ ) else "" end -}} |
| 101 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 102 | +RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat |
| 103 | +ENTRYPOINT ["docker-entrypoint.sh"] |
| 104 | + |
| 105 | +{{ if env.version != "5.6" then ( -}} |
| 106 | +EXPOSE 3306 33060 |
| 107 | +{{ ) else ( -}} |
| 108 | +EXPOSE 3306 |
| 109 | +{{ ) end -}} |
| 110 | +CMD ["mysqld"] |
0 commit comments